抱歉,上传文件时出错

时间:2017-01-29 09:33:49

标签: php file upload

我正在上传php中的文件,并在出现错误后获取。

抱歉,上传文件时出错。

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
    print($target_file);
    echo "Sorry, there was an error uploading your file.";
}

如何解决此错误?

2 个答案:

答案 0 :(得分:0)

使用print_r($_FILES)来调试问题。

您的输出是:

  

数组([fileToUpload] =>数组([name] => origdata_c.n..xlsx [type]   => [tmp_name] => [错误] => 1 [size] => 0))

根据手册,错误键的值为1表示:

http://php.net/manual/en/features.file-upload.errors.php

  

UPLOAD_ERR_INI_SIZE(值1)

     

上传的文件超过了php.ini中的upload_max_filesize指令。

因此,解决方案应该是增加php.ini中的upload_max_filesize配置。

答案 1 :(得分:0)

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        print($target_file)."<br>";
        echo "Sorry, there was an error uploading your file.";
    }
}