If $_FILES[$field]['tmp_name']
is empty then the file hasn’t been uploaded. You should look at $_FILES[$field]['error']
to see why.
FWIW, and as far as I understand it, the mime-type in $_FILES[]
is provided by the browser.
Update: here is a bit of potted code to handle all file upload errors:
$message="Error uploading file";
switch( $_FILES['newfile']['error'] ) {
case UPLOAD_ERR_OK:
$message = false;;
break;
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
$message .= ' - file too large (limit of '.get_max_upload().' 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['newfile']['error'];
break;
}
if( !$message ) {
if( !is_uploaded_file($_FILES['newfile']['tmp_name']) ) {
$message="Error uploading file - unknown error.";
} else {
// Let's see if we can move the file...
$dest .= "https://stackoverflow.com/".$this_file;
if( !move_uploaded_file($_FILES['newfile']['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.";
}
}
}