PHP 5.3.5 fileinfo() MIME Type for MS Office 2007 files - magic.mime updates?

≡放荡痞女 提交于 2019-12-01 20:53:37

Newer Office files are actually ZIP archives. That's why MIME Magic database is detecting them as ZIP files. You may need to add special rules based on file extension, or look into the ZIP file to see if it has a docProps folder (Office ZIP archives have such a folder containing meta data about the document).

There are other file formats which are actually ZIP archives with a different extension, e.g. JAR files.

  1. Yes, you should update magic.mime.

lol, yeah, just update it, problem solved. Unfortunately, it looks like the magic mime type systems works off of looking at the actual file contents, and because the file is compressed, it can't uncompress (and look at which file?)

someone suggested writing a function to unzip compressed files and then checking for the existence of a "DocProps" directory, for instance. But this would introduce another vector of attack to the production server.

Have you tried to add the new mime types to IIS ?

  1. Get to the Internet Management snap-in
  2. Right click “Web Sites” and select “Properties”
  3. Select “HTTP Headers”
  4. Select “Mime Types”
  5. Enter a new extension with no leading period and the appropriate mime type. Repeat as needed for each extension.
  6. Click “OK” to close all the dialogs
  1. Yes, you should update magic.mime.
  2. Thumb up for not believing mime type sent from browser ($_FILES['Filedata']['type'])
  3. Why you are using a function that the manual said it's deprecated? http://php.net/manual/en/function.mime-content-type.php

Note: finfo() determine the MIME type of a file by it's magic bytes; given the fact that Office 2007 files (and many other file formats, e.g. ePUB) are simply zip packages with specified directory structure, it's reasonable to have finfo() to return application/zip.

I would suggest unzip or list the content to inspect it's structure, if you really want to determinate the file type based on it's content (and not the MIME type browser reports when uploading)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!