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 : 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.
Options> Environment > MIME Types can be found under Tools > Options. You can select aMIME type from the MIME Type field. By clicking on the name of the editing editor you wish to use again, Handler will display a context-menu to open that file. How Do I Change A File Type In Linux?
The file extension may override the MIME type, but the file will still be usable without a file extension thanks its MIME type information. Your web browser and email client also rely on MIME types.
MIME types are fairly simple, although they can seem like black magic to a new Linux or Mac user. They do provide more freedom when it comes to naming your files — you can name documents, pictures, and videos whatever you want on Linux, removing file extensions if you want to.
The information identifying these files is read from the compiled magic file /usr/share/file/magic.mgc, or /usr/share/file/magic if the compile file does not exist. In addition file will look in $HOME/.magic.mgc, or $HOME/.magic for magic entries.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With