mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 08:44:07 -04:00
use file extension for determining mimetypes on default
should be more reliable for files that "look like" other types based on their magic numbers such as odf and docx files also a lot faster then the old way
This commit is contained in:
parent
ab8ce89df3
commit
2a73678fef
3 changed files with 25 additions and 39 deletions
|
|
@ -345,18 +345,24 @@ class OC_Helper {
|
|||
*/
|
||||
static function getMimeType($path){
|
||||
$isWrapped=(strpos($path,'://')!==false) and (substr($path,0,7)=='file://');
|
||||
$mimeType='application/octet-stream';
|
||||
if ($mimeType=='application/octet-stream') {
|
||||
self::$mimetypes = include('mimetypes.fixlist.php');
|
||||
$extension=strtolower(strrchr(basename($path), "."));
|
||||
$extension=substr($extension,1);//remove leading .
|
||||
$mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream';
|
||||
|
||||
}
|
||||
if (@is_dir($path)) {
|
||||
// directories are easy
|
||||
return "httpd/unix-directory";
|
||||
}
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
if($mimeType=='application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)){
|
||||
$info = @strtolower(finfo_file($finfo,$path));
|
||||
if($info){
|
||||
|
|
@ -385,15 +391,6 @@ class OC_Helper {
|
|||
}
|
||||
|
||||
}
|
||||
if ($mimeType=='application/octet-stream') {
|
||||
// Fallback solution: (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';
|
||||
}
|
||||
return $mimeType;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
return array(
|
||||
'ics'=>'text/calendar',
|
||||
'ical'=>'text/calendar',
|
||||
'js'=>'application/javascript',
|
||||
'odt'=>'application/vnd.oasis.opendocument.text',
|
||||
'ods'=>'application/vnd.oasis.opendocument.spreadsheet',
|
||||
'odg'=>'application/vnd.oasis.opendocument.graphics',
|
||||
'odp'=>'application/vnd.oasis.opendocument.presentation',
|
||||
'pl'=>'text/x-script.perl',
|
||||
'py'=>'text/x-script.phyton',
|
||||
'vcf' => 'text/vcard',
|
||||
'vcard' => 'text/vcard',
|
||||
'doc'=>'application/msword',
|
||||
'docx'=>'application/msword',
|
||||
'xls'=>'application/msexcel',
|
||||
'xlsx'=>'application/msexcel',
|
||||
'ppt'=>'application/mspowerpoint',
|
||||
'pptx'=>'application/mspowerpoint',
|
||||
'sgf' => 'application/sgf',
|
||||
'cdr' => 'application/coreldraw'
|
||||
);
|
||||
|
|
@ -78,5 +78,16 @@ return array(
|
|||
'mpeg'=>'video/mpeg',
|
||||
'mov'=>'video/quicktime',
|
||||
'webm'=>'video/webm',
|
||||
'wmv'=>'video/x-ms-asf'
|
||||
'wmv'=>'video/x-ms-asf',
|
||||
'py'=>'text/x-script.phyton',
|
||||
'vcf' => 'text/vcard',
|
||||
'vcard' => 'text/vcard',
|
||||
'doc'=>'application/msword',
|
||||
'docx'=>'application/msword',
|
||||
'xls'=>'application/msexcel',
|
||||
'xlsx'=>'application/msexcel',
|
||||
'ppt'=>'application/mspowerpoint',
|
||||
'pptx'=>'application/mspowerpoint',
|
||||
'sgf' => 'application/sgf',
|
||||
'cdr' => 'application/coreldraw',
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue