Handling file upload errors
suggest changeThe $_FILES["FILE_NAME"]['error'] (where "FILE_NAME" is the value of the name attribute of the file input, present in your form) might contain one of the following values:
UPLOAD_ERR_OK- There is no error. The file was uploaded.UPLOAD_ERR_INI_SIZE- The uploaded file exceeds theupload_max_filesizedirective inphp.ini.UPLOAD_ERR_FORM_SIZE- The uploaded file exceeds theMAX_FILE_SIZEvalue that was specified in the HTML form.UPLOAD_ERR_PARTIAL- The file was only partially uploaded.UPLOAD_ERR_NO_FILE- No file was uploaded.UPLOAD_ERR_NO_TMP_DIR- Missing a temporary folder. (From PHP 5.0.3.)UPLOAD_ERR_CANT_WRITE- Failed to write the file to disk. (From PHP 5.1.0.)UPLOAD_ERR_EXTENSION- A PHP extension stopped the file upload. (From PHP 5.2.0.)
A basic way to check the errors is:
<?php
$fileError = $_FILES["FILE_NAME"]["error"]; // where FILE_NAME is the name attribute of the file input in your form
switch($fileError) {
case UPLOAD_ERR_OK:
// The file was uploaded
break;
case UPLOAD_ERR_INI_SIZE:
// Exceeds upload_max_filesize in php.ini
break;
case UPLOAD_ERR_FORM_SIZE:
// Exceeds MAX_FILE_SIZE in the HTML form
break;
case UPLOAD_ERR_PARTIAL:
// The file was only partially uploaded
break;
case UPLOAD_ERR_NO_FILE:
// No file was uploaded
break;
case UPLOAD_ERR_NO_TMP_DIR:
// No temporary directory to write to
break;
case UPLOAD_ERR_CANT_WRITE:
// Error writing to disk
break;
case UPLOAD_ERR_EXTENSION:
// An extension stopped the upload
break;
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents