seperate mimetype guessing from filename
This commit is contained in:
parent
81b6cab94f
commit
cf7321915d
|
@ -363,6 +363,26 @@ class OC_Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to guess the mimetype based on filename
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
static public function getFileNameMimeType($name){
|
||||||
|
if(strpos($path, '.')) {
|
||||||
|
//try to guess the type by the file extension
|
||||||
|
if(!self::$mimetypes || self::$mimetypes != include 'mimetypes.list.php') {
|
||||||
|
self::$mimetypes=include 'mimetypes.list.php';
|
||||||
|
}
|
||||||
|
$extension=strtolower(strrchr(basename($path), "."));
|
||||||
|
$extension=substr($extension, 1);//remove leading .
|
||||||
|
$mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream';
|
||||||
|
}else{
|
||||||
|
$mimeType='application/octet-stream';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the mimetype form a local file
|
* get the mimetype form a local file
|
||||||
* @param string $path
|
* @param string $path
|
||||||
|
@ -377,17 +397,7 @@ class OC_Helper {
|
||||||
return "httpd/unix-directory";
|
return "httpd/unix-directory";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strpos($path, '.')) {
|
$mimeType = self::getFileNameMimeType($path);
|
||||||
//try to guess the type by the file extension
|
|
||||||
if(!self::$mimetypes || self::$mimetypes != include 'mimetypes.list.php') {
|
|
||||||
self::$mimetypes=include 'mimetypes.list.php';
|
|
||||||
}
|
|
||||||
$extension=strtolower(strrchr(basename($path), "."));
|
|
||||||
$extension=substr($extension, 1);//remove leading .
|
|
||||||
$mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream';
|
|
||||||
}else{
|
|
||||||
$mimeType='application/octet-stream';
|
|
||||||
}
|
|
||||||
|
|
||||||
if($mimeType=='application/octet-stream' and function_exists('finfo_open')
|
if($mimeType=='application/octet-stream' and function_exists('finfo_open')
|
||||||
and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)) {
|
and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)) {
|
||||||
|
|
Loading…
Reference in New Issue