From: Robin Appelman Date: Thu, 6 Jun 2013 21:51:44 +0000 (+0200) Subject: seperate mimetype guessing from filename X-Git-Tag: v6.0.0alpha2~622^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cf7321915d3913888e03e0624b32296194a91e6e;p=nextcloud-server.git seperate mimetype guessing from filename --- diff --git a/lib/helper.php b/lib/helper.php index 225e9fd2a9a..c3dc8740ee8 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -364,19 +364,12 @@ class OC_Helper { } /** - * get the mimetype form a local file - * @param string $path + * Try to guess the mimetype based on filename + * + * @param string $name * @return string - * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead */ - static function getMimeType($path) { - $isWrapped=(strpos($path, '://')!==false) and (substr($path, 0, 7)=='file://'); - - if (@is_dir($path)) { - // directories are easy - return "httpd/unix-directory"; - } - + 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') { @@ -388,6 +381,23 @@ class OC_Helper { }else{ $mimeType='application/octet-stream'; } + } + + /** + * get the mimetype form a local file + * @param string $path + * @return string + * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead + */ + static function getMimeType($path) { + $isWrapped=(strpos($path, '://')!==false) and (substr($path, 0, 7)=='file://'); + + if (@is_dir($path)) { + // directories are easy + return "httpd/unix-directory"; + } + + $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/';