0

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

4 Answers 4

4

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']];
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @Danijel for such detail answer
1

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

Comments

1

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.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.