Detail error return value in PHP $_FILES
- 2020-12-20 03:31:20
- OfStack
$_FILES [' file] [' error] value
UPLOAD_ERR_OK: 0 // Normal, upload successful
UPLOAD_ERR_INI_SIZE: 1 // The upload file size exceeds the maximum allowed by the server. In ES14en.ini, set the value limited by the upload_max_filesize option
UPLOAD_ERR_FORM_SIZE: 2 // Upload file size exceeding the value specified by the hidden field MAX_FILE_SIZE option in the HTML form
UPLOAD_ERR_NO_TMP_DIR: 6 // Temporary folder could not be found
UPLOAD_ERR_CANT_WRITE: 7 // file write failed
UPLOAD_ERR_EXTENSION: 8 //php file upload extension is not open
UPLOAD_ERR_PARTIAL: 3 // The file was only partially uploaded
UPLOAD_ERR_OK: 0 // Normal, upload successful
UPLOAD_ERR_INI_SIZE: 1 // The upload file size exceeds the maximum allowed by the server. In ES14en.ini, set the value limited by the upload_max_filesize option
UPLOAD_ERR_FORM_SIZE: 2 // Upload file size exceeding the value specified by the hidden field MAX_FILE_SIZE option in the HTML form
UPLOAD_ERR_NO_TMP_DIR: 6 // Temporary folder could not be found
UPLOAD_ERR_CANT_WRITE: 7 // file write failed
UPLOAD_ERR_EXTENSION: 8 //php file upload extension is not open
UPLOAD_ERR_PARTIAL: 3 // The file was only partially uploaded
switch($_FILES[$field]['error']) {
case 1:
// The file size exceeds the server's space size
$this->setError("The file is too large (server).");
break;
case 2:
// The file size to upload exceeds the browser limit
$this->setError("The file is too large (form).");
break;
case 3:
// The file is only partially uploaded
$this->setError("The file was only partially uploaded.");
break;
case 4:
// No file to upload was found
$this->setError("No file was uploaded.");
break;
case 5:
// Server temporary folder missing
$this->setError("The servers temporary folder is missing.");
break;
case 6:
// Error writing file to temporary folder
$this->setError("Failed to write to the temporary folder.");
break;
}