how to expand magic.mime on linux
I'm trying to allow safe upload of files and I'm using php 5.3 Fileinfo to do so. This uses the magic.mime file on our Centos system.
The problem is that TTF fonts, OTF, EOT, SVG, ... files aren't recognized as such and it defaults back to "application/octet-stream" as the mime type.
This is not safe for me, as this can be just about any file such as an executable. My question is: can I get a magic.mime file which contains definitions for the files above or even better: is there a consistent method or approach to add new mime types ourselves to the magic.mime file so that we can easily expand this file when we want to check for a new type of file.
I did a search for what package provides the magic.mime file:
yum whatprovides "/usr/share/magic.mime"
Name : file
Arch : i386
Version : 4.17
Release : 15.el5_3.1
Size : 1.6 M
Repo 开发者_StackOverflow社区 : installed
Summary : A utility for determining file types.
URL : http://www.darwinsys.com/file/
The problem is that CentOS doesn't install the latest FILE package so I cannot update the file that way.
I also have file-4.17 which uses /usr/share/file/magic. I could not update the file command, and PEAR mime_type uses magic same as PHP fileinfo. So, only solution I found was to edit magic.mime (after backing it up) and adding the unrecognized type manually (FLV in my case). Then you need to do a file -C -m magic.mime
to compile it. There's another stackoverflow topic that covers the same process:How to create a custom magic file database
精彩评论