Added workaround for libmagic issues
authorMarcel Werk <burntime@woltlab.com>
Fri, 14 Mar 2014 02:55:45 +0000 (03:55 +0100)
committerMarcel Werk <burntime@woltlab.com>
Fri, 14 Mar 2014 02:55:45 +0000 (03:55 +0100)
wcfsetup/install/files/lib/system/upload/UploadHandler.class.php

index 7527ccec57620fd5eb6af41952b496ea52756963..d264f1df8b960d2d8f23ee7202d52c8bf6b571ac 100644 (file)
@@ -54,11 +54,11 @@ class UploadHandler {
                        
                        // multiple uploads
                        for ($i = 0, $l = count($rawFileData['name']); $i < $l; $i++) {
-                               $this->files[] = new UploadFile($rawFileData['name'][$i], $rawFileData['tmp_name'][$i], $rawFileData['size'][$i], $rawFileData['error'][$i], ($rawFileData['tmp_name'][$i] ? (FileUtil::getMimeType($rawFileData['tmp_name'][$i]) ?: $rawFileData['type'][$i]) : ''));
+                               $this->files[] = new UploadFile($rawFileData['name'][$i], $rawFileData['tmp_name'][$i], $rawFileData['size'][$i], $rawFileData['error'][$i], ($rawFileData['tmp_name'][$i] ? (self::getMimeType($rawFileData['tmp_name'][$i], $rawFileData['type'][$i])) : ''));
                        }
                }
                else {
-                       $this->files[] = new UploadFile($rawFileData['name'], $rawFileData['tmp_name'], $rawFileData['size'], $rawFileData['error'], ($rawFileData['tmp_name'] ? (FileUtil::getMimeType($rawFileData['tmp_name']) ?: $rawFileData['type']) : ''));
+                       $this->files[] = new UploadFile($rawFileData['name'], $rawFileData['tmp_name'], $rawFileData['size'], $rawFileData['error'], ($rawFileData['tmp_name'] ? (self::getMimeType($rawFileData['tmp_name'], $rawFileData['type'])) : ''));
                }
        }
        
@@ -123,4 +123,23 @@ class UploadHandler {
                
                return null;
        }
+       
+       /**
+        * Returns the mime type of a file.
+        * 
+        * @param       string          $file
+        * @param       string          $mimeType       mime type transferred by client
+        * @return      string
+        */
+       protected static function getMimeType($file, $mimeType) {
+               if ($mimeType == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' || $mimeType == 'application/vnd.openxmlformats-officedocument.presentationml.presentation' || $mimeType == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
+                       // libmagic can not detect mime type of docx, xlsx and pttx files
+                       return $mimeType;
+               }
+               
+               $finfoMimeType = FileUtil::getMimeType($file);
+               if ($finfoMimeType) return $finfoMimeType;
+               
+               return $mimeType;
+       }
 }