diff options
author | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2012-10-26 21:02:04 +0300 |
---|---|---|
committer | Victor Dubiniuk <victor.dubiniuk@gmail.com> | 2012-10-26 21:02:04 +0300 |
commit | d428d72dabf1d0f451f5dedc8e7e5cc654e04ffb (patch) | |
tree | a3c92fc380fbfdfc9985ec209d1ed28ac924c20f | |
parent | ad720c4c17867df24de0dc55453efd0eea8b9a17 (diff) | |
download | nextcloud-server-d428d72dabf1d0f451f5dedc8e7e5cc654e04ffb.tar.gz nextcloud-server-d428d72dabf1d0f451f5dedc8e7e5cc654e04ffb.zip |
Fix mimetype detection with the 'file' utility
-rw-r--r-- | lib/helper.php | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/lib/helper.php b/lib/helper.php index b7166e9fb41..2da06c4cc45 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -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; |