$_FILES field 'tmp_name' has no value on .JPG file extension
Solution 1:
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 .= '/'.$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.';
}
}
}
Solution 2:
Check your php.ini
and in particular this setting
; Maximum allowed size for uploaded files.
; http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize
upload_max_filesize = 6M
Or do this in your Apache Config:
<Directory "/var/www/vhosts/path/to/your/directory/import/">
php_value post_max_size 6M
php_value upload_max_filesize 6M
</Directory>
I would also say that it is poor that PHP doesn't report an error in the error logs if you upload a file that is larger than your php.ini upload_max_filesize
setting. For example, if you upload a 6MB file when you have it set at 2M
(which I think is the default).