NYCPHP Meetup

NYPHP.org

[nycphp-talk] Checking 'mime type' of local file

Jon Baer jonbaer at jonbaer.com
Fri May 11 12:09:00 EDT 2007


The interesting part is the magic db which file does use ...

G5:~ jonbaer$ egrep "jpeg|png|gif" /usr/share/file/magic.mime
0       string          GIF             image/gif
0       beshort         0xffd8          image/jpeg
0       string          \x89PNG                 image/png
G5:/~ jonbaer$

Also it has been recently updated (if you want to update your  
mime_magic.magicfile directive) ...

ftp://ftp.astron.com/pub/file/

- Jon

On May 11, 2007, at 11:39 AM, csnyder wrote:

> On 5/10/07, Jon Baer <jonbaer at jonbaer.com> wrote:
>> What you're really looking for the is the 'magic' of the bin file.
>>
>> http://en.wikipedia.org/wiki/Magic_number_%28programming%29
>>
>> There is a PECL extension for diving into libmagic ...
>>
>> http://pecl.php.net/package/Fileinfo
>>
>
> In the past, I've made use of the unix file command for this.
>
> csnyder$ file -bi Desktop/DSC01060.jpg
> image/jpeg
>
> Command above uses -b for brief, and -i to get the mimetype of the  
> file.
>
> -- 
> Chris Snyder
> http://chxo.com/
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php




More information about the talk mailing list