Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <icewind1991@gmail.com>2011-10-23 13:26:54 +0400
committerRobin Appelman <icewind1991@gmail.com>2011-10-23 13:35:29 +0400
commit122fa190c684d953c1f11930109ca6644fde485c (patch)
tree92ba46614a5db1a15053b24b33ce9deb062fd005 /lib/filestorage
parent38bb503ff6fd07fe5c65e5f06add98663d9cdf3e (diff)
improve mimetype detection
Diffstat (limited to 'lib/filestorage')
-rw-r--r--lib/filestorage/local.php21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index 58c34e972de..01523b6b0b3 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -126,18 +126,21 @@ class OC_Filestorage_Local extends OC_Filestorage{
public function getMimeType($fspath){
if($this->is_readable($fspath)){
+ $mimeType='application/octet-stream';
if (@is_dir($this->datadir.$fspath)) {
// directories are easy
return "httpd/unix-directory";
- }elseif (function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)){
+ }
+ if($mimeType=='application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)){
$mimeType =strtolower(finfo_file($finfo,$this->datadir.$fspath));
$mimeType=substr($mimeType,0,strpos($mimeType,';'));
finfo_close($finfo);
- return $mimeType;
- } else if (function_exists("mime_content_type")) {
+ }
+ if ($mimeType=='application/octet-stream' && function_exists("mime_content_type")) {
// use mime magic extension if available
- $mime_type = mime_content_type($this->datadir.$fspath);
- } else if (OC_Helper::canExecute("file")) {
+ $mimeType = mime_content_type($this->datadir.$fspath);
+ }
+ if ($mimeType=='application/octet-stream' && OC_Helper::canExecute("file")) {
// it looks like we have a 'file' command,
// lets see it it does have mime support
$fspath=str_replace("'","\'",$fspath);
@@ -146,18 +149,18 @@ class OC_Filestorage_Local extends OC_Filestorage{
pclose($fp);
//trim the character set from the end of the response
- $mime_type=substr($reply,0,strrpos($reply,' '));
+ $mimeType=substr($reply,0,strrpos($reply,' '));
}
- if (empty($mime_type)) {
+ if ($mimeType=='application/octet-stream') {
// Fallback solution: (try to guess the type by the file extension
if(!self::$mimetypes){
self::$mimetypes=include('mimetypes.list.php');
}
$extention=strtolower(strrchr(basename($fspath), "."));
$extention=substr($extention,1);//remove leading .
- $mime_type=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream';
+ $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream';
}
- return $mime_type;
+ return $mimeType;
}
}