Fix mimetype detection with the 'file' utility
This commit is contained in:
parent
ad720c4c17
commit
d428d72dab
|
@ -373,20 +373,15 @@ class OC_Helper {
|
||||||
}
|
}
|
||||||
if (!$isWrapped and $mimeType=='application/octet-stream' && OC_Helper::canExecute("file")) {
|
if (!$isWrapped and $mimeType=='application/octet-stream' && OC_Helper::canExecute("file")) {
|
||||||
// it looks like we have a 'file' command,
|
// 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);
|
$path=escapeshellarg($path);
|
||||||
$fp = popen("file -i -b $path 2>/dev/null", "r");
|
$fp = popen("file -i -b $path 2>/dev/null", "r");
|
||||||
$reply = fgets($fp);
|
$reply = fgets($fp);
|
||||||
pclose($fp);
|
pclose($fp);
|
||||||
|
|
||||||
//trim the character set from the end of the response
|
// we have smth like 'text/x-c++; charset=us-ascii\n'
|
||||||
$mimeType=substr($reply,0, strrpos($reply,' '));
|
// and need to eliminate everything starting with semicolon including trailing LF
|
||||||
$mimeType=substr($mimeType,0, strrpos($mimeType,"\n"));
|
$mimeType = preg_replace('/;.*/ms', '', trim($reply));
|
||||||
|
|
||||||
//trim ;
|
|
||||||
if (strpos($mimeType, ';') !== false) {
|
|
||||||
$mimeType = strstr($mimeType, ';', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return $mimeType;
|
return $mimeType;
|
||||||
|
|
Loading…
Reference in New Issue