Welcome Guest, Not a member yet? Register   Sign In
trouble with file_mime_type() in upload.php
#1

(This post was last modified: 02-09-2018, 10:33 AM by richb201.)

    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? 
proof that an old dog can learn new tricks
Reply
#2

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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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'),
proof that an old dog can learn new tricks
Reply
#4

I understand that, I was giving all of the other ones to try.
Sometimes the web gets them wrong and another type will work.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(This post was last modified: 02-10-2018, 06:01 AM by richb201.)

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?
proof that an old dog can learn new tricks
Reply
#6

php.net - finfo_file
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

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.
proof that an old dog can learn new tricks
Reply
#8

Glad you figured it out.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB