$ _FILES中的某些键为空

时间:2019-02-20 12:20:01

标签: php html

因此,我正在为我妈妈的网站工作,她想从她的相机上传照片,我首先用在photoshop CS6和$ _FILES数组中创建的计算机上找到的普通图片测试了代码。还可以:

array ( 'img' => array ( 'name' => array ( 0 => 'pic01.jpg', ), 'type' => array ( 0 => 'image/jpeg', ), 'tmp_name' => array ( 0 => 'D:\\xampp\\tmp\\phpF0F7.tmp', ), 'error' => array ( 0 => 0, ), 'size' => array ( 0 => 6311, ), ), )

但是当我尝试上传手机和她的手机的照片时,会得到以下数组:

array ( 'img' => array ( 'name' => array ( 0 => 'IMG_20180228_143837.jpg', ), 'type' => array ( 0 => '', ), 'tmp_name' => array ( 0 => '', ), 'error' => array ( 0 => 1, ), 'size' => array ( 0 => 0, ), ), )

如您所见,类型,tmp_name和大小为空或不正确(大小不正确)。我还看到错误数组的值从0更改为1。

这两个数组导出均由var_export($_FILES);

完成

我使用以下HTML代码上传图片:

<form method="post" action="updateproduct.php" enctype="multipart/form-data">{
      <input name="img[]" id="fileupload" type="file" multiple />

我希望我能提供足够的信息,否则请说。

2 个答案:

答案 0 :(得分:2)

function resetShadow() { var distance = $("#slider-distance").slider("value"); var direction = $("#slider-direction").slider("value"); var offsetX = distance - (direction); var offsetY = Math.cos(direction*Math.PI/180) * distance + 10 circle.setShadow({ color: '#5b238A', blur: 20, offsetX: offsetX, offsetY: offsetY }); canvas.renderAll(); } 数组中的错误值1表示您已超出服务器施加的文件大小限制:

  

UPLOAD_ERR_INI_SIZE

     

值:1;上传的文件超出了php.ini中的upload_max_filesize指令。

Source

答案 1 :(得分:1)

默认情况下,PHP仅接受under 2MB的文件上传。考虑在您的PHP配置(php.ini)中将其更改为更实际的内容(例如200MB)。同样不要忘记增加另一个相关选项post_max_size,该选项应该比upload_max_filesize大一些。

顺便说一句,这是一个不错的helper function,它将编码的错误转换为人类可读的消息:

    function codeToMessage($code) 
    { 
        switch ($code) { 
            case UPLOAD_ERR_INI_SIZE: 
                $message = "The uploaded file exceeds the upload_max_filesize directive in php.ini"; 
                break; 
            case UPLOAD_ERR_FORM_SIZE: 
                $message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form";
                break; 
            case UPLOAD_ERR_PARTIAL: 
                $message = "The uploaded file was only partially uploaded"; 
                break; 
            case UPLOAD_ERR_NO_FILE: 
                $message = "No file was uploaded"; 
                break; 
            case UPLOAD_ERR_NO_TMP_DIR: 
                $message = "Missing a temporary folder"; 
                break; 
            case UPLOAD_ERR_CANT_WRITE: 
                $message = "Failed to write file to disk"; 
                break; 
            case UPLOAD_ERR_EXTENSION: 
                $message = "File upload stopped by extension"; 
                break; 

            default: 
                $message = "Unknown upload error"; 
                break; 
        } 
        return $message; 
    }