Enhance mime detection
This commit is contained in:
parent
ebf39acf5b
commit
d6e4880ee6
@ -162,12 +162,14 @@ function dol_compare_file($a, $b)
|
|||||||
* Return mime type of a file
|
* Return mime type of a file
|
||||||
* @param file Filename
|
* @param file Filename
|
||||||
* @param default Default mime type if extension not found in known list
|
* @param default Default mime type if extension not found in known list
|
||||||
|
* @param shortmime Return short mime, otherwise full mime string
|
||||||
* @return string Return a mime type family
|
* @return string Return a mime type family
|
||||||
* (text/xxx, application/xxx, image/xxx, audio, video, archive)
|
* (text/xxx, application/xxx, image/xxx, audio, video, archive)
|
||||||
*/
|
*/
|
||||||
function dol_mimetype($file,$default='application/octet-stream')
|
function dol_mimetype($file,$default='application/octet-stream',$shortmime=0)
|
||||||
{
|
{
|
||||||
$mime=$default;
|
$mime=$default;
|
||||||
|
|
||||||
// Text files
|
// Text files
|
||||||
if (preg_match('/\.txt$/i',$file)) $mime='text/plain';
|
if (preg_match('/\.txt$/i',$file)) $mime='text/plain';
|
||||||
if (preg_match('/\.rtx$/i',$file)) $mime='text/richtext';
|
if (preg_match('/\.rtx$/i',$file)) $mime='text/richtext';
|
||||||
@ -225,9 +227,21 @@ function dol_mimetype($file,$default='application/octet-stream')
|
|||||||
if (preg_match('/\.(avi|divx|xvid|wmv|mpg|mpeg)$/i',$file)) $mime='video';
|
if (preg_match('/\.(avi|divx|xvid|wmv|mpg|mpeg)$/i',$file)) $mime='video';
|
||||||
// Archive
|
// Archive
|
||||||
if (preg_match('/\.(zip|rar|gz|tgz|z|cab|bz2|7z|tar|lzh)$/i',$file)) $mime='archive'; // application/xxx where zzz is zip, ...
|
if (preg_match('/\.(zip|rar|gz|tgz|z|cab|bz2|7z|tar|lzh)$/i',$file)) $mime='archive'; // application/xxx where zzz is zip, ...
|
||||||
|
// Exe
|
||||||
|
if (preg_match('/\.(exe|com)$/i',$file)) $mime='application';
|
||||||
|
// Exe
|
||||||
|
if (preg_match('/\.(dll|lib|o|so|a)$/i',$file)) $mime='library';
|
||||||
|
|
||||||
|
if ($shortmime)
|
||||||
|
{
|
||||||
|
$tmp=explode('/',$mime);
|
||||||
|
return $tmp[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return $mime;
|
return $mime;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user