trouble with file_mime_type() in upload.php - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: trouble with file_mime_type() in upload.php (/showthread.php?tid=70014) |
trouble with file_mime_type() in upload.php - richb201 - 02-09-2018 I've uploaded an xls file and I seem to be getting the wrong mime type for it. This is the line of trouble: $mime = @finfo_file($finfo, $file['tmp_name']); The $mime says that it is a "text/plain;charset=utf-16le" but the screenshot attached shows that it is actually a "vnd.ms-excel". After this it is all downhill. A few lines down (line 1241 of upload.php) if (is_string($mime) && preg_match($regexp, $mime, $matches)) { $this->file_type = $matches[1]; return; } This causes the file_type to be text when I am only allowing XLS | XLSX. Any ideas on what to do? RE: trouble with file_mime_type() in upload.php - InsiteFX - 02-09-2018 You can always add Mime Type to ./application/config/mimes.php Code: Excel Mime Types: RE: trouble with file_mime_type() in upload.php - richb201 - 02-09-2018 Thanks. As you can see, vnd.ms-excel already exists (first one) in mimes.php: 'xls' => array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'), RE: trouble with file_mime_type() in upload.php - InsiteFX - 02-10-2018 I understand that, I was giving all of the other ones to try. Sometimes the web gets them wrong and another type will work. RE: trouble with file_mime_type() in upload.php - richb201 - 02-10-2018 Perhaps I need to try some other way? I really don't want to hack up upload.php, that would be unmaintainable. Perhaps I could turn off the mimes checking? How can I debug @finfo_file? Where can I find that code? Is that a built in php function? How about the character part? Do you know what that is? How about the "magic file"? What is that? Or is that the mimes.php we have talked about? RE: trouble with file_mime_type() in upload.php - InsiteFX - 02-10-2018 php.net - finfo_file RE: trouble with file_mime_type() in upload.php - richb201 - 02-10-2018 Found it, I think! Turns out that I had extension=php_fileinfo.dll <<<<<<< I am using php5.6 and you don't need this dll in version of php after 5.3. I guess there was some kind of conflict going on between the built in finfo code and the finfo code in the dll Thanks for your help. RE: trouble with file_mime_type() in upload.php - InsiteFX - 02-10-2018 Glad you figured it out. |