views:

68

answers:

3

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
A: 

Parse your Apache's mime.types file.

Amadan
+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
`apache_lookup_uri` does not give you a MIME type, AFAIK. FileInfo will work, if you have PECL, as noted by @David.
Amadan
apache_lookup_uri amongst other things returns 'content_type' which is the mime-type
nathan
@nathan: Ah. Duh. :)
Amadan