PHP error messages while uploading file

Some times while uploading a file through PHP you may encounter some errors. These errors can be accessed by the $_FILES[<field_name>][‘error’].

The $_FILES[<field_name>][‘error’] returns the error number i.e. from 0-8. If you receive 0 then all is fine and the file has uploaded successfully. If other than 0 then most probably it is an issue with hosting and nothing to do with coding.

Please see following error codes and their descriptions as provided by the PHP manual

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

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

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

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

Value: 4; No file was uploaded.

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

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

Value: 8; File upload stopped by extension. Introduced in PHP 5.2.0.

Hope the above helps

Leave a Comment