[BUGFIX] Crash after file upload on Windows without finfo 66/17466/4
authorChristian Weiske <christian.weiske@netresearch.de>
Fri, 11 Jan 2013 15:52:54 +0000 (16:52 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 6 Feb 2013 11:24:05 +0000 (12:24 +0100)
This patch checks if the finfo extension is available before using it
to determine the MIME type of a file.
If it is not available, the old function mime_content_type is used as
fallback.
When none of them are available, we give up.

This fixes a crash on Windows after uploading a file, since finfo
is by default not installed on PHP windows distributions.

Change-Id: I53a0eef3ee839c17ddaaeb303b9a0b9bae3ee485
Fixes: #37440
Releases: 6.0, 6.1
Reviewed-on: https://review.typo3.org/17466
Reviewed-by: Philipp Gampe
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php

index d693d96..36aca82 100644 (file)
@@ -520,14 +520,19 @@ class LocalDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
        }
 
        /**
-        * Get mime type of file.
+        * Get MIME type of file.
         *
         * @param string $absoluteFilePath Absolute path to file
-        * @return string Mime type. eg, text/html
+        * @return string|boolean MIME type. eg, text/html, FALSE on error
         */
        protected function getMimeTypeOfFile($absoluteFilePath) {
-               $fileInfo = new \finfo();
-               return $fileInfo->file($absoluteFilePath, FILEINFO_MIME_TYPE);
+               if (function_exists('finfo_file')) {
+                       $fileInfo = new \finfo();
+                       return $fileInfo->file($absoluteFilePath, FILEINFO_MIME_TYPE);
+               } elseif (function_exists('mime_content_type')) {
+                       return mime_content_type($absoluteFilePath);
+               }
+               return FALSE;
        }
 
        /**