1

I have a problem with MIME-type while uploading a file to server from the web-interface. I used CI as engine for my website. I have FreeBSD with Apache 2.2.15 on the board.
The problem is:

  1. While i upload doc-file, i get application/x-msword, ppt - application/vnd.ms-powerpoint, xls - application/vnd.ms-excel - this is normal.
  2. But when i try to upload docx, pptx, xlsx i get application/octet-stream; rar - application/force-download - and this is wrong.

UPD1. In my mime.types file these MIME-types are present with required type (ie. application/openxmlformats-officedocument.wordprocessingml.document)
UPD2. I wrote "AddType app.../openxml... .docx" in httpd.conf directly and restart apache, but nothing happened.
UPD3. Upload form has enctype "multipart/form-mixed"
UPD4. Content-type in Firebug`s NET-panel have a wrong MIME-type also

kirillorloff
  • 47
  • 2
  • 7
  • I've no idea what 'CI' is. Are you sure its not storing the mimetype that the file was uploaded with? Did you edit /etc/mime.types or the mime types config file for Apache (they may not be the same)? – symcbean Jul 26 '10 at 16:26
  • CI means "CodeIgniter" - PHP framework. I edit apache22/mime.types config file. – kirillorloff Jul 26 '10 at 16:37
  • Your question is so unclear. What do you actually mean when you say "i get application/x-msword"? How do you get it? Why should apache httpd care what type of file you upload? – Max Kosyakov Jul 28 '10 at 05:27
  • I use Firebug`s function `fb()` to get info about `$_FILES`. There is the variable `type` in this array - that is how i get MIME-type "application/x-msword". So, who should care? AFAIK, while uploading, my files are passing through Apache first. Why he has table of mime-types (mime.types)? – kirillorloff Jul 28 '10 at 16:36
  • It looks like you just did not read the manual! http://www.php.net/manual/en/features.file-upload.post-method.php – Max Kosyakov Aug 20 '10 at 05:28

2 Answers2

1

This is because .docx files are actually ZIP files with a different extension. If you open one of them up in WinRAR or WinZIP you'll find dozens of .xml files inside them. My guess is that FreeBSD is not aware of the difference between a .docx and a .zip file, because they're the same thing.

That said, I'm really not sure what you're asking or what you're trying to achieve.

Mark Henderson
  • 68,823
  • 31
  • 180
  • 259
  • In system mime.types FreeBSD knows difference between `.docx` & `.zip`. My aim is right recognizing MIME-types by Apache (or PHP - load as mod_php). Nor `force-download`, neither `octet-stream` for MIME-types that has "apache22/mime.types". – kirillorloff Jul 28 '10 at 16:43
1

I don't know about the CodeIgniter Framework, but I do know that I have seen a couple PHP based applications that have this problem. If you fire up wireshark and sniff the HTTP taffic you may see that the computer that uploads the file is setting the wrong MIME type. If your PHP application blindly assumes that the uploader knows the correct type there may not be much you can do.

Zoredache
  • 130,897
  • 41
  • 276
  • 420
  • Yeah, when i sniff HTTP-headers, i see wrong Content-type sendind to server (UPD4). That is a question - what should i do to get right Content-type OR right MIME-type? How i can "teach" default PHP uploader to recognize right type? – kirillorloff Jul 28 '10 at 16:39
  • I haven't found a good solution yet... :| But I haven't really been working because it isn't that important of an issue on the system I saw it. A solution to the problem may have to be altering the PHP code and making a special exception for docx types. – Zoredache Jul 28 '10 at 16:52
  • I haven't found a good solution too! Maybe, you know how Apache and/or FreeBSD determines MIME-type? – kirillorloff Jul 28 '10 at 21:12