Skip to content

Instantly share code, notes, and snippets.

@Ephigenia
Created October 18, 2011 11:59
Show Gist options
  • Select an option

  • Save Ephigenia/1295266 to your computer and use it in GitHub Desktop.

Select an option

Save Ephigenia/1295266 to your computer and use it in GitHub Desktop.
PHP-upload-file-errors
// test if a file was uploaded
$formFieldName = 'myFile';
if (isset($_FILES[$formFieldName])) {
switch(@$_FILES[$formFieldName]['error']) {
case UPLOAD_ERR_OK: // 0
// everything is ok with the upload for php
break;
case UPLOAD_ERR_INI_SIZE:
// file is larger than the size set in php.ini
// upload_max_filesize
break;
case UPLOAD_ERR_FORM_SIZE:
// file exceeds size set in form
break;
case UPLOAD_ERR_PARTIAL:
// file upload
break;
case UPLOAD_ERR_NO_FILE:
// no file was specified (empty form field)
break;
case UPLOAD_ERR_NO_TMP_DIR:
// no tmp dir specified in php.ini
break;
case UPLOAD_ERR_CANT_WRITE:
// tmp dir from php.ini is not writable for php
break;
default:
// unknown error code
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment