A problem with large file uploads and $_FILE['file']['type']
Posted: Fri Apr 10, 2009 5:31 pm
I'm having a problem with file upload from post. I'm setting the $_FILES variable and can successfully upload a small pdf file that is mime-type validated with following bit of code:
Where...
$ext is the extension
$this->accept is a list of known mime-types.
$this->accept[$ext] returns the mime type for the given extension.
I obtain the file and call check_type with the following:
foreach($_FILES as $file) {
if ($file['name']) { // skip empty file_0
if ($fu->check_type($file)) {
On large files (for example pdf files several MB in size) I receive an error 'file type does not match file extension. Expecting type: application/pdf. Found type: Comp615BookPart1.pdf
$file['type'] should be the file's mime-type from everything I've read. I'm not sure why I'm getting the file name here.
It's only happening on large pdf files. I've made sure php.ini has been set to handle files of that size.
I've found that the browser is responsible for filling out the parameters on the file. I am currently using Firefox 3.0.8 (latest version as of 4/10/09).
Any ideas would be greatly appreciated.
Where...
$ext is the extension
$this->accept is a list of known mime-types.
$this->accept[$ext] returns the mime type for the given extension.
I obtain the file and call check_type with the following:
foreach($_FILES as $file) {
if ($file['name']) { // skip empty file_0
if ($fu->check_type($file)) {
Code: Select all
public function check_type($file) { // get file type
$ext = pathinfo($file['name'],PATHINFO_EXTENSION);
// make sure the image is a valid file type and that the type matches the extention
if (!array_key_exists($ext,$this->accept)) {
$this->_error = 'invalid file type';
return false;
} elseif ($this->accept[$ext] != $file['type']) {
$this->_error = 'file type does not match file extension. Expecting type: '.$this->accept[$ext].'. Found type: '.$file['type'];
return false;
} else {
return true;
}
}
$file['type'] should be the file's mime-type from everything I've read. I'm not sure why I'm getting the file name here.
It's only happening on large pdf files. I've made sure php.ini has been set to handle files of that size.
I've found that the browser is responsible for filling out the parameters on the file. I am currently using Firefox 3.0.8 (latest version as of 4/10/09).
Any ideas would be greatly appreciated.