]> source.dussan.org Git - nextcloud-server.git/commitdiff
add function to get mimetype from string
authorRobin Appelman <icewind@owncloud.com>
Wed, 18 Apr 2012 18:24:22 +0000 (20:24 +0200)
committerRobin Appelman <icewind@owncloud.com>
Wed, 18 Apr 2012 18:54:28 +0000 (20:54 +0200)
lib/helper.php

index eed94917767417d1e5587bdd3713cfd94e5ed040..beb10280d935996781631c687950046a9dc06515 100755 (executable)
@@ -353,6 +353,26 @@ class OC_Helper {
                return $mimeType;
        }
 
+       /**
+        * get the mimetype form a data string
+        * @param string data
+        * @return string
+        */
+       static function getStringMimeType($data){
+               if(function_exists('finfo_open') and function_exists('finfo_file')){
+                       $finfo=finfo_open(FILEINFO_MIME);
+                       return finfo_buffer($finfo, $data);
+               }else{
+                       $tmpFile=OC_Helper::tmpFile();
+                       $fh=fopen($tmpFile,'wb');
+                       fwrite($fh,$data,8024);
+                       fclose($fh);
+                       $mime=self::getMimeType($tmpFile);
+                       unset($tmpFile);
+                       return $mime;
+               }
+       }
+
        /**
         * @brief Checks $_REQUEST contains a var for the $s key. If so, returns the html-escaped value of this var; otherwise returns the default value provided by $d.
         * @param $s name of the var to escape, if set.