diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-07-22 01:49:42 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-07-22 01:53:20 +0200 |
commit | 2a73678fef47f8230f6caf546e42b22d722973b0 (patch) | |
tree | c926dce2b4dd77b349e54f3676da87cfd62da336 /lib/helper.php | |
parent | ab8ce89df34ea1fefd457973fd80651dba72a278 (diff) | |
download | nextcloud-server-2a73678fef47f8230f6caf546e42b22d722973b0.tar.gz nextcloud-server-2a73678fef47f8230f6caf546e42b22d722973b0.zip |
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
Diffstat (limited to 'lib/helper.php')
-rw-r--r-- | lib/helper.php | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/lib/helper.php b/lib/helper.php index c4f7e8b2e19..59d88f46dad 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -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; } |