How to see the error message in $_FILE array in PHP

大兔子大兔子 提交于 2020-01-06 15:29:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!