For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > April 2005 > Re: FW: [PHP-DB] mime-type related to extension?. .









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: FW: [PHP-DB] mime-type related to extension?. .
Martin Norland

2005-04-27, 3:56 pm

meal list_php wrote:
> Hi I sent this on 21st of april and got no answer...
> there is no way to check the "real" mime type of a file?
> even a file without extension?
> thanks,


You can call out to an external program called "file" (which is pretty
much guaranteed to be there, on a Linux system) which uses some magic to
determine the file type. It should be able to tell you if the file is
jpeg regardless, without any messy work from you. It will return a
string like so:
$ file false.doc
false.doc: JPEG image data, JFIF standard 1.02
I'd run a few tests with some images from different sources, but it
should be returning a very standard string - "JPEG image data" should at
least be common. IIRC Sony also has a 'motion jpeg' which might cause
you problems, depending on what you're doing - if you can get a hold of
one of those to test (if it's a concern) you might want to.

cheers,
--
- Martin Norland, Sys Admin / Database / Web Developer, International
Outreach x3257
The opinion(s) contained within this email do not necessarily represent
those of St. Jude Children's Research Hospital.
Matthew Weier O'Phinney

2005-04-27, 3:56 pm

* Martin Norland <martin.norland@stjude.org>:
> meal list_php wrote:
>
> You can call out to an external program called "file" (which is pretty
> much guaranteed to be there, on a Linux system) which uses some magic to
> determine the file type. It should be able to tell you if the file is
> jpeg regardless, without any messy work from you. It will return a
> string like so:
> $ file false.doc
> false.doc: JPEG image data, JFIF standard 1.02
> I'd run a few tests with some images from different sources, but it
> should be returning a very standard string - "JPEG image data" should at
> least be common. IIRC Sony also has a 'motion jpeg' which might cause
> you problems, depending on what you're doing - if you can get a hold of
> one of those to test (if it's a concern) you might want to.


An additional tool that may be used when simply checking for image types
is to use getimagesize() -- though you should be using php >= 4.3.11 to
do this safely (see http://security.gentoo.org/glsa/glsa-200504-15.xml
for more information). One element returned by getimagesize() is the
image MIME type.

--
Matthew Weier O'Phinney | WEBSITES:
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org
mailto:matthew@garden.org | http://vermontbotanical.org
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com