util.inc: Default to static extension lookup
Magic can return invalid results for video files, breaking their playback. Default to the static extension lookup to avoid this problem but still return application/octet-stream if nothing works.
This commit is contained in:
parent
0663bf54a0
commit
52718b0590
@ -509,6 +509,27 @@ function captcha_check() {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function getMimeType($file, $ext="") {
|
function getMimeType($file, $ext="") {
|
||||||
|
|
||||||
|
// Static extension lookup
|
||||||
|
$ext = strtolower($ext);
|
||||||
|
static $exts = array(
|
||||||
|
'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png',
|
||||||
|
'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ico' => 'image/x-icon',
|
||||||
|
'swf' => 'application/x-shockwave-flash', 'pdf' => 'application/pdf',
|
||||||
|
'zip' => 'application/zip', 'gz' => 'application/x-gzip',
|
||||||
|
'tar' => 'application/x-tar', 'bz' => 'application/x-bzip',
|
||||||
|
'bz2' => 'application/x-bzip2', 'txt' => 'text/plain',
|
||||||
|
'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html',
|
||||||
|
'css' => 'text/css', 'js' => 'text/javascript',
|
||||||
|
'xml' => 'text/xml', 'xsl' => 'application/xsl+xml',
|
||||||
|
'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav',
|
||||||
|
'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg',
|
||||||
|
'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php',
|
||||||
|
'mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isset($exts[$ext])) { return $exts[$ext]; }
|
||||||
|
|
||||||
$type = false;
|
$type = false;
|
||||||
// Fileinfo documentation says fileinfo_open() will use the
|
// Fileinfo documentation says fileinfo_open() will use the
|
||||||
// MAGIC env var for the magic file
|
// MAGIC env var for the magic file
|
||||||
@ -531,24 +552,7 @@ function getMimeType($file, $ext="") {
|
|||||||
|
|
||||||
if ($type !== false && strlen($type) > 0) return $type;
|
if ($type !== false && strlen($type) > 0) return $type;
|
||||||
|
|
||||||
// Otherwise do it the old fashioned way
|
return 'application/octet-stream';
|
||||||
$ext = strtolower($ext);
|
|
||||||
static $exts = array(
|
|
||||||
'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png',
|
|
||||||
'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ico' => 'image/x-icon',
|
|
||||||
'swf' => 'application/x-shockwave-flash', 'pdf' => 'application/pdf',
|
|
||||||
'zip' => 'application/zip', 'gz' => 'application/x-gzip',
|
|
||||||
'tar' => 'application/x-tar', 'bz' => 'application/x-bzip',
|
|
||||||
'bz2' => 'application/x-bzip2', 'txt' => 'text/plain',
|
|
||||||
'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html',
|
|
||||||
'css' => 'text/css', 'js' => 'text/javascript',
|
|
||||||
'xml' => 'text/xml', 'xsl' => 'application/xsl+xml',
|
|
||||||
'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav',
|
|
||||||
'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg',
|
|
||||||
'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php',
|
|
||||||
'mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm'
|
|
||||||
);
|
|
||||||
return isset($exts[$ext]) ? $exts[$ext] : 'application/octet-stream';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user