I have local access to files, which I need to get their MIME types. Working in WAMP/LAMP, CodeIgniter, and Zend libraries. What's the best way to get MIME type information?
+3
A:
There's no easy way. You could try:
http://www.php.net/manual/en/function.finfo-file.php
// return mime type ala mimetype extension
$finfo = finfo_open(FILEINFO_MIME_TYPE);
Of course, this assumes you can install PECL extensions.
David Titarenco
2010-07-07 02:55:58
+1
A:
I think you need head. Quickest way is to do a head request, or in PHP under apache you can use apache_lookup_uri or in PHP 5.3 you can use FileInfo (I'd still recommend apache_lookup_uri or a simple head request though).
nathan
2010-07-07 02:58:50
`apache_lookup_uri` does not give you a MIME type, AFAIK. FileInfo will work, if you have PECL, as noted by @David.
Amadan
2010-07-07 03:10:57
apache_lookup_uri amongst other things returns 'content_type' which is the mime-type
nathan
2010-07-07 11:33:21
@nathan: Ah. Duh. :)
Amadan
2010-07-10 15:28:17