CodeIgniter Forums
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:

application/vnd.ms-excel (official)
application/msexcel
application/x-msexcel
application/x-ms-excel
application/x-excel
application/x-dos_ms_excel
application/xls
application/x-xls
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (xlsx)

Office Mime Type:

Ext      MIME Type

.doc     application/msword
.dot     application/msword
.docx    application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx    application/vnd.openxmlformats-officedocument.wordprocessingml.template
.docm    application/vnd.ms-word.document.macroEnabled.12
.dotm    application/vnd.ms-word.template.macroEnabled.12
.xls     application/vnd.ms-excel
.xlt     application/vnd.ms-excel
.xla     application/vnd.ms-excel
.xlsx    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx    application/vnd.openxmlformats-officedocument.spreadsheetml.template
.xlsm    application/vnd.ms-excel.sheet.macroEnabled.12
.xltm    application/vnd.ms-excel.template.macroEnabled.12
.xlam    application/vnd.ms-excel.addin.macroEnabled.12
.xlsb    application/vnd.ms-excel.sheet.binary.macroEnabled.12
.ppt     application/vnd.ms-powerpoint
.pot     application/vnd.ms-powerpoint
.pps     application/vnd.ms-powerpoint
.ppa     application/vnd.ms-powerpoint
.pptx    application/vnd.openxmlformats-officedocument.presentationml.presentation
.potx    application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx    application/vnd.openxmlformats-officedocument.presentationml.slideshow
.ppam    application/vnd.ms-powerpoint.addin.macroEnabled.12
.pptm    application/vnd.ms-powerpoint.presentation.macroEnabled.12
.potm    application/vnd.ms-powerpoint.presentation.macroEnabled.12
.ppsm    application/vnd.ms-powerpoint.slideshow.macroEnabled.12



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.