问题
I am working on multiple file upload functionality where I am getting error when I print the file array as:
print_r($_FILE);
Gets error as:
Array
(
[name] => _agiewniki_Forrest_in_Autumn.jpg
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)
I don't see the error description, the error only this
[error] => 1
回答1:
You can use this array to display file-upload error messages:
$error_messages = array(
UPLOAD_ERR_OK => 'There is no error, the file uploaded with success',
UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini',
UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded',
UPLOAD_ERR_NO_FILE => 'No file was uploaded',
UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder',
UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk',
UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload',
);
// prints "The uploaded file exceeds the upload_max_filesize directive in php.ini"
echo $error_messages[$_FILES['error']];
回答2:
http://www.php.net/manual/en/features.file-upload.errors.php
UPLOAD_ERR_INI_SIZE Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
Hope to help
回答3:
Here you can find by the code of error the description
In your case it is: The uploaded file exceeds the upload_max_filesize directive in php.ini.
回答4:
Based on the $_FILES['userfile']['error'] value you can print the respective error message in the ref document.
Add all the error messages in some array with respective error key value. Based on the error key value received from the $_FILE during upload, and show the respective error message[Link added below].
Error Messages Explained :
Error Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
For more & Ref: http://www.php.net/manual/en/features.file-upload.errors.php
来源:https://stackoverflow.com/questions/20835175/how-to-see-the-error-message-in-file-array-in-php