June 14, 2009

How to install php extension FileInfo and get a file MIME type

Just a little post that may help PHP developers. It works under Ubuntu Hardy Heron Server and PHP version < 5.3.

When developing in PHP, you need sometimes to get informations about a file, especially the MIME type ( ex : text/plain, image/gif ).

In order to do so, you need first, to install the PECL extension FileInfo. ( Since PHP 5.3, the FileInfo extension is packaged by default.)

Here is the following command lines to install this extension:

and then copy the code to get the file MIME type :

Hope it helps :)

More resources about MIME types :
http://en.wikipedia.org/wiki/MIME
http://www.iana.org/assignments/media-types/

Comments (View)
blog comments powered by Disqus