PHP: File Upload Error Code CodeUnit 21 NOV 2010

When handling file uploads via enctype=”multipart/form-data” forms in PHP, you’ll be pleased to know that PHP doesn’t just leave you high and dry but instead returns some pretty helpful error codes to let you know when something goes wrong.

The following is a comprehensive listing of the error codes returned by the upload process:

(Note, these can be access from $_FILES[‘#inputname#’][‘error’])

  • 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 4.3.10 and 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; File upload stopped by extension. Introduced in PHP 5.2.0.

And there you go, now you know! :)

Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.