Hi,
If you're using a recent enough version of PHP (ie 5.3) or have the possibility to install PECL extensions, you should take a look at the Fileinfo extension, that's bundled with PHP 5.3.
Quoting one of the given examples, a portion of code like this one :
<?php
$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
foreach (glob("*") as $filename) {
echo finfo_file($finfo, $filename) . "\n";
}
finfo_close($finfo);
?>
Might get you something like this :
text/html
image/gif
application/vnd.ms-excel
If you're stuck with an older version of PHP, and cannot install PECL extensions, maybe the mime_content_type
function would do.