上传图片PHP问题

时间:2011-08-15 15:27:33

标签: php image upload

大家好,我正在使用此代码http://www.w3schools.com/php/php_file_upload.asp上传文件,但效果很好,但现在我正在制作一个带有可选图片的表单,它不会让我上传。它说这是一种无效的文件格式,因为它根本就没有文件。如何检查是否有要上传的文件,如果没有,则跳过上传脚本?

谢谢!

注意:如果有任何不同之处,我已从脚本中删除了大小限制。

2 个答案:

答案 0 :(得分:2)

if ($_FILES['nameofyourfileinput']['error'] === UPLOAD_ERR_OK) {
   ... file has been uploaded and everything went ok ...
} else if ($_FILES['nameofyourfieinput']['error'] !== UPLOAD_ERR_NO_FILE) {
   ... something OTHER than a 'no file was uploaded' error has occured...
}

上传错误代码here

答案 1 :(得分:0)

检查文件错误代码是否不是4; http://php.net/manual/en/features.file-upload.errors.php