From cf7321915d3913888e03e0624b32296194a91e6e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 6 Jun 2013 23:51:44 +0200 Subject: [PATCH] seperate mimetype guessing from filename --- lib/helper.php | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/helper.php b/lib/helper.php index 225e9fd2a9..c3dc8740ee 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -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 * @param string $path @@ -377,17 +397,7 @@ class OC_Helper { 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'; - } + $mimeType = self::getFileNameMimeType($path); if($mimeType=='application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)) { @@ -609,7 +619,7 @@ class OC_Helper { } /** - * remove all files in PHP /oc-noclean temp dir + * remove all files in PHP /oc-noclean temp dir */ public static function cleanTmpNoClean() { $tmpDirNoCleanFile=get_temp_dir().'/oc-noclean/';