diff options
author | Robin Appelman <icewind1991@gmail.com> | 2010-09-08 02:01:30 +0200 |
---|---|---|
committer | Robin Appelman <icewind1991@gmail.com> | 2010-09-08 02:04:07 +0200 |
commit | 420178bec8d7716ee855af07b7a95fea972ac05c (patch) | |
tree | f83daad3e14a319c5ba82b7ca13e5a1a70017748 | |
parent | cffa4edb722b080091cb417b734dbff1907eafb2 (diff) | |
download | nextcloud-server-420178bec8d7716ee855af07b7a95fea972ac05c.tar.gz nextcloud-server-420178bec8d7716ee855af07b7a95fea972ac05c.zip |
fix fallback for mimetype detection using the 'file' command
-rw-r--r-- | inc/lib_filestorage.php | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/inc/lib_filestorage.php b/inc/lib_filestorage.php index 62532916ca5..3e53e266279 100644 --- a/inc/lib_filestorage.php +++ b/inc/lib_filestorage.php @@ -223,22 +223,12 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ } else if (self::canExecute("file")) { // it looks like we have a 'file' command, // lets see it it does have mime support - $fp = popen("file -i '$fspath' 2>/dev/null", "r"); + $fp = popen("file -i -b '{$this->datadir}$fspath' 2>/dev/null", "r"); $reply = fgets($fp); pclose($fp); - // popen will not return an error if the binary was not found - // and find may not have mime support using "-i" - // so we test the format of the returned string - - // the reply begins with the requested filename - if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) { - $reply = substr($reply, strlen($fspath)+2); - // followed by the mime type (maybe including options) - if (preg_match('/^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*/', $reply, $matches)) { - $mime_type = $matches[0]; - } - } + //trim the character set from the end of the response + $mime_type=substr($reply,0,strrpos($reply,' ')); } if (empty($mime_type)) { // Fallback solution: try to guess the type by the file extension |