]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix mimetype detection with the 'file' utility
authorVictor Dubiniuk <victor.dubiniuk@gmail.com>
Fri, 26 Oct 2012 18:02:04 +0000 (21:02 +0300)
committerVictor Dubiniuk <victor.dubiniuk@gmail.com>
Fri, 26 Oct 2012 18:02:04 +0000 (21:02 +0300)
lib/helper.php

index b7166e9fb411d1df8e333ebdde30c0f1f0183d84..2da06c4cc454df9ab07bab2f6902aec272a2adb4 100644 (file)
@@ -373,20 +373,15 @@ class OC_Helper {
                }
                if (!$isWrapped and $mimeType=='application/octet-stream' && OC_Helper::canExecute("file")) {
                        // it looks like we have a 'file' command,
-                       // lets see it it does have mime support
+                       // lets see if it does have mime support
                        $path=escapeshellarg($path);
                        $fp = popen("file -i -b $path 2>/dev/null", "r");
                        $reply = fgets($fp);
                        pclose($fp);
 
-                       //trim the character set from the end of the response
-                       $mimeType=substr($reply,0, strrpos($reply,' '));
-                       $mimeType=substr($mimeType,0, strrpos($mimeType,"\n"));
-
-                       //trim ;
-                       if (strpos($mimeType, ';') !== false) {
-                               $mimeType = strstr($mimeType, ';', true);
-                       }
+                       // we have smth like 'text/x-c++; charset=us-ascii\n'
+                       // and need to eliminate everything starting with semicolon including trailing LF
+                       $mimeType = preg_replace('/;.*/ms', '', trim($reply));
 
                }
                return $mimeType;