When working with PHP $_FILES array we get an array of uploaded files and in that array you will find a key of error with a numerical value that tells us what went wrong during file upload process. An example of $_FILES array can be found below.
Array
(
[filename] => Array
(
[name] => WordPress-56-img.jpg
[type] => image/jpeg
[tmp_name] => C:\xampp\tmp\php88B6.tmp
[error] => 0
[size] => 322401
)
)
In above array you can see [error] => 0 meaning there is no error in file upload and everything went well. However there are more error code to handle. For example in code below error code is 4 meaning no file was selected during form submit.
Array
(
[filename] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
)
Here are more error numbers with their meaning
Value | Meaning |
---|---|
0 | No error. Everything went well |
1 | File exceeded upload_max_filesize in php.ini configuration |
2 | Exceeded MAX_FILE_SIZE limit set in hidden form field |
3 | Only partially uploaded |
4 | No file was uploaded |
6 | No temporary upload folder set |
7 | Problem/fail to write to disk |
8 | A PHP extension prevented the upload |
Note that there is no error code 5!