[thelist] PHP File Uploading, Macintosh, and Mime Types
Mike Migurski
mike at saturn5.com
Tue Dec 10 16:53:01 CST 2002
>Among other information, I'm storing these files' mime types in a mysql
>database. Initially, I was grabbing the mime types from uploaded files
>from the $_FILES array ($_FILES[...]['type']), but I realized this wasn't
>going to work from files added in other ways. So instead I created a
>general function, return_mime_type($path), that uses the UNIX command
>"file -ib $path" to return the mime type of a local file. I figured this
>was the best way - a standard method of returning mime types on all files
>added into the asset management system.
why not use a multi-step approach?
1) use the _FILES array if it's available to you, since its info will
probably be the most reliable and available.
2) failing that, use the output of `file`
3) failing that, check the file extension and make an educated guess.
(this is what Apache does, anyway [I think])
4) failing that, store it as a generic file, or complain to the user that
more information is required.
---------------------------------------------------------------------
michal migurski- contact info and pgp key:
http://www.saturn5.com/mike/contact.html
"Freedom! Horrible, horrible freedom!"
More information about the thelist
mailing list