Created
October 22, 2014 18:22
-
-
Save jfreites/a6cee5768f53fa022eb7 to your computer and use it in GitHub Desktop.
Check errors uploading file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$message = 'Error uploading file'; | |
switch( $_FILES['file']['error'] ) { | |
case UPLOAD_ERR_OK: | |
$message = false;; | |
break; | |
case UPLOAD_ERR_INI_SIZE: | |
case UPLOAD_ERR_FORM_SIZE: | |
$message .= ' - file too large (limit of '. ini_get('upload_max_filesize') .' bytes).'; | |
break; | |
case UPLOAD_ERR_PARTIAL: | |
$message .= ' - file upload was not completed.'; | |
break; | |
case UPLOAD_ERR_NO_FILE: | |
$message .= ' - zero-length file uploaded.'; | |
break; | |
default: | |
$message .= ' - internal error #'.$_FILES['file']['error']; | |
break; | |
} | |
if( !$message ) { | |
if( !is_uploaded_file($_FILES['file']['tmp_name']) ) { | |
$message = 'Error uploading file - unknown error.'; | |
} else { | |
$dest .= '/'; // folder path | |
if( !move_uploaded_file($_FILES['file']['tmp_name'], $dest) ) { // No error supporession so we can see the underlying error. | |
$message = 'Error uploading file - could not save upload (this will probably be a permissions problem in '.$dest.')'; | |
} else { | |
$message = 'File uploaded okay.'; | |
} | |
} | |
echo $message; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment