From: Marcel Werk Date: Fri, 14 Mar 2014 02:55:45 +0000 (+0100) Subject: Added workaround for libmagic issues X-Git-Tag: 2.0.4~10 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=01301c6e30e63ca5a50288408133b1df7a0e6c06;p=GitHub%2FWoltLab%2FWCF.git Added workaround for libmagic issues --- diff --git a/wcfsetup/install/files/lib/system/upload/UploadHandler.class.php b/wcfsetup/install/files/lib/system/upload/UploadHandler.class.php index 7527ccec57..d264f1df8b 100644 --- a/wcfsetup/install/files/lib/system/upload/UploadHandler.class.php +++ b/wcfsetup/install/files/lib/system/upload/UploadHandler.class.php @@ -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; + } }