Custom File Upload Error Messages

You can set custom error messages using the built-in php upload error constants.

$upload_errors = array (
      UPLOAD_ERR_OK         => 'No errors.',
      UPLOAD_ERR_INI_SIZE   => 'Larger then upload_max_filesize.',
      UPLOAD_ERR_FORM_SIZE  => 'File size is to large!',
      UPLOAD_ERR_PARTIAL    => 'Resume partially uploaded!',
      UPLOAD_ERR_NO_FILE    => 'You must upload a resume!',
      UPLOAD_ERR_NO_TMP_DIR => 'Temporary directory does not exist!',
      UPLOAD_ERR_CANT_WRITE => "Can't write to disk!",
      UPLOAD_ERR_EXTENSION  => 'File upload stopped by extension!'


// After form post get file info
$file = $_FILES['uploaded_file'];

// If there was an error during upload then display custom message
 if ($file['error'] != 0) {
     echo $upload_errors[$file['error']]);

Leave a comment