Welcome Guest, Not a member yet? Register   Sign In
File Upload type and mimes (a solution + office 2007 mime code/icons)
#1

[eluser]echadwickb[/eluser]
I spent hours the last few days troubleshooting a really annoying file upload problem. Had a user email me asking why her powerpoint 2007 file wouldn't upload to the doc management program I wrote.

Easy fix, right? Wrong! First step was to add the 5 billion Office 2007 file extensions to my controller method:

docx|docm|dotx|dotm|xlsx|xlsm|xltx|xltm|xlsb|xlam|pptx|pptm|potx|potm|ppam|ppsx|ppsm

(your welcome)

I then grabbed all the office 2007 document icons in gif format:

http://www.therightstuff.de/2006/12/16/O...+2003.aspx

(your welcome again)

Still wasn't working for her. She kept getting the file type not allowed message. I suddenly remembered the config/mimes.php. I added the mimes to the file . . .

Code:
$mimes = array( 'docm'     =>     'application/vnd.ms-word.document.macroenabled.12',
                'docx'     =>     'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                'dotm'     =>     'application/vnd.ms-word.template.macroenabled.12',
                'dotx'     =>     'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
                'potm'     =>     'application/vnd.ms-powerpoint.template.macroenabled.12',
                'potx'     =>     'application/vnd.openxmlformats-officedocument.presentationml.template',
                'ppam'     =>     'application/vnd.ms-powerpoint.addin.macroenabled.12',
                'ppsm'     =>     'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
                'ppsx'     =>     'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
                'pptm'     =>     'application/vnd.ms-powerpoint.presentation.macroenabled.12',
                'pptx'     =>     'application/vnd.openxmlformats-officedocument.presentationml.presentation',
                'xlam'     =>     'application/vnd.ms-excel.addin.macroenabled.12',
                'xlsb'     =>     'application/vnd.ms-excel.sheet.binary.macroenabled.12',
                'xlsm'     =>     'application/vnd.ms-excel.sheet.macroenabled.12',
                'xlsx'     =>     'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
                'xltm'     =>     'application/vnd.ms-excel.template.macroenabled.12',
                'xltx'     =>     'application/vnd.openxmlformats-officedocument.spreadsheetml.template'
);

(aren't I a giving person :p)

Still no dice. After hours of testing and searching these forums, I finally gave in and looked at the file_upload class (1.6.1). Turns out the class runs the uploaded file's mime type through strtolower. The mimes I copied into my mimes.php file had capital letters. I did a text replace, and it worked (the code above has already been text replaced).

Just thought I would share this with everyone else. It's not the first time that case sensitivity bit me on the a** . . . probably won't be the last either.
#2

[eluser]xwero[/eluser]
Thanks for the contribution, but are all browsers identifying the mimes like that?
#3

[eluser]echadwickb[/eluser]
good question. I don't know honestly. From reading these forums, it appears that there is some discrepancy between how browsers report mime types to the server. I can at least vouch for firefox 3 and IE7 working with these types in our environment.

I'm going to have to update this app eventually. If I ever get around to it, I'll try to put in the legwork to find out.
#4

[eluser]mkhairul[/eluser]
I also tried to upload an office document (excel) with the extension xlsx. It kept telling me the filetype is not allowed. I look at the upload value and the filetype is \"application/octet-stream\" instead of just application/octet-stream.

I have no idea why this is happening but I just added the string inside the mimetype.
Code:
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/octet-stream', '\"application/octet-stream\"'),

Now it works. Anyone have any idea why this is happening?
#5

[eluser]echadwickb[/eluser]
this issue has been covered in forums before. I ran into it when I was researching my problem. I believe it has to do with how certain browsers (possibly firefox?) report mime types. It's a little over my head. If I can find a link to one of those threads, I'll post it here.
#6

[eluser]heenji[/eluser]
i have the same problem when i want to upload a xml file,it failed!. then i just check the $_FILES,find the file_type is application/octet-stream,then modify the mime.php in config,modify
Code:
'xml'    =>    'text/xml',
to
Code:
'xml'    =>    array('text/xml','application/xml','application/octet-stream'),
,then ok,you could try it.
#7

[eluser]Zeeshan Rasool[/eluser]
Same issue is with my code, i couldn't upload the office 2007 file please give any solution Thanks A lot !
#8

[eluser]zwadder[/eluser]
I tried the above solution but it didn't work, did some digging in the CI_Upload class and did found out that not all types were loaded, did change the order of the allowed types and this did the trick.




Theme © iAndrew 2016 - Forum software by © MyBB