public static function mimetype($filename)
{
$mimetype = null;
if (function_exists('finfo_open') && file_exists($filename)) {
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_file($finfo, $filename);
/* FILEINFO_MIME Returns the mime type and mime encoding as defined by RFC 2045.
* So only return the mime type, not the encoding.
*/
if (($pos = strpos($mimetype, ';')) !== false) {
$mimetype = substr($mimetype, 0, $pos);
}
finfo_close($finfo);
}
if (empty($mimetype)) {
$pi = pathinfo($filename);
switch (strtolower($pi['extension'])) {
// hacky, hacky, kludge, kludge...
case 'jpg':
case 'jpeg':
$mimetype = 'image/jpeg';
break;
case 'gif':
$mimetype = 'image/gif';
break;
case 'png':
$mimetype = 'image/png';
break;
case 'mp3':
$mimetype = 'audio/mpeg3';
break;
case 'wav':
$mimetype = 'audio/wav';
break;
case 'mpg':
case 'mpeg':
$mimetype = 'video/mpeg';
break;
case 'swf':
$mimetype = 'application/x-shockwave-flash';
break;
case 'htm':
case 'html':
$mimetype = 'text/html';
break;
}
}
$mimetype = Plugins::filter('get_mime_type', $mimetype, $filename);
return $mimetype;
}