-2

Here i have one array, in that array i want to take only error,how can take the value of error, I am new PHP developer i tried but i am not getting the answer i tried like this echo $_FILES['file']['error'],but is not printing the output

print_r($_FILES)

Array
(
[file] => Array
    (
        [name] => Array
            (
                [0] => 1.png
            )

        [type] => Array
            (
                [0] => image/png
            )

        [tmp_name] => Array
            (
                [0] => C:\xampp5.6\tmp\php96F6.tmp
            )

        [error] => Array
            (
                [0] => 0
            )

        [size] => Array
            (
                [0] => 166275
            )

    )

   )
3
  • try print_r($_FILES['file']) Commented Nov 1, 2017 at 11:36
  • php.net/manual/en/features.file-upload.errors.php [error] => Array ( [0] => 0 ) your upload didn't fail (yet). As per the manual "Value: 0; There is no error, the file uploaded with success." Commented Nov 1, 2017 at 11:37
  • This is mere php 101. You have the output dump array.besides the upload went through successfully. To fully comprehend how arrays work and how to iterate, you need to go back to the roots of php tutorials Commented Nov 1, 2017 at 11:38

2 Answers 2

1

Error 0 means the upload was successful.

The codes are (from http://php.net/manual/en/features.file-upload.errors.php):

UPLOAD_ERR_OK Value: 0; There is no error, the file uploaded with success.

UPLOAD_ERR_INI_SIZE Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.

UPLOAD_ERR_FORM_SIZE Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

UPLOAD_ERR_PARTIAL Value: 3; The uploaded file was only partially uploaded.

UPLOAD_ERR_NO_FILE Value: 4; No file was uploaded.

UPLOAD_ERR_NO_TMP_DIR Value: 6; Missing a temporary folder. Introduced in PHP 5.0.3.

UPLOAD_ERR_CANT_WRITE Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.

UPLOAD_ERR_EXTENSION Value: 8; A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help. Introduced in PHP 5.2.0.

In your case you get the error from $_FILES['file']['error'][0] and then find that 0 means UPLOAD_ERR_OK — there is no error.

If you don't check for the error, then you will find that http://php.net/manual/en/function.move-uploaded-file.php won't work.

Sign up to request clarification or add additional context in comments.

Comments

0

If you just want to get the error value then this code will help you.

$error = $_FILES['file']['error'][0];

1 Comment

Maybe add more explanation as OP is a newbie

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.