]> source.dussan.org Git - nextcloud-server.git/commitdiff
seperate mimetype guessing from filename
authorRobin Appelman <icewind@owncloud.com>
Thu, 6 Jun 2013 21:51:44 +0000 (23:51 +0200)
committerRobin Appelman <icewind@owncloud.com>
Thu, 6 Jun 2013 21:51:44 +0000 (23:51 +0200)
lib/helper.php

index 225e9fd2a9a439e7903d1e6bbc8ddf0c08206078..c3dc8740ee814950e17bf4138b0ad1b700a5f9bd 100644 (file)
@@ -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/';