Skip to content
Snippets Groups Projects
Commit d428d72d authored by Victor Dubiniuk's avatar Victor Dubiniuk
Browse files

Fix mimetype detection with the 'file' utility

parent ad720c4c
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment