summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2016-10-31 15:19:46 +0100
committerAndrey Andreev <narf@devilix.net>2016-10-31 15:19:46 +0100
commit7cc08237c2a15daf283e2bc61501bdc086740311 (patch)
treeba9f1f57122cd19852387d57768d54bc25e4cbd9
parent6b5464c5b8a97268aab3814b56a1413a9463a97f (diff)
[ci skip] Fix #4887
-rw-r--r--system/libraries/Upload.php36
-rw-r--r--user_guide_src/source/changelog.rst1
2 files changed, 24 insertions, 13 deletions
diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php
index 23fd02ead..778ed6892 100644
--- a/system/libraries/Upload.php
+++ b/system/libraries/Upload.php
@@ -1218,21 +1218,31 @@ class CI_Upload {
// We'll need this to validate the MIME info string (e.g. text/plain; charset=us-ascii)
$regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/';
- // Fileinfo extension - most reliable method
- $finfo = @finfo_open(FILEINFO_MIME);
- if (is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system
+ /**
+ * Fileinfo extension - most reliable method
+ *
+ * Apparently XAMPP, CentOS, cPanel and who knows what
+ * other PHP distribution channels EXPLICITLY DISABLE
+ * ext/fileinfo, which is otherwise enabled by default
+ * since PHP 5.3 ...
+ */
+ if (function_exists('finfo_file'))
{
- $mime = @finfo_file($finfo, $file['tmp_name']);
- finfo_close($finfo);
-
- /* According to the comments section of the PHP manual page,
- * it is possible that this function returns an empty string
- * for some files (e.g. if they don't exist in the magic MIME database)
- */
- if (is_string($mime) && preg_match($regexp, $mime, $matches))
+ $finfo = @finfo_open(FILEINFO_MIME);
+ if (is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system
{
- $this->file_type = $matches[1];
- return;
+ $mime = @finfo_file($finfo, $file['tmp_name']);
+ finfo_close($finfo);
+
+ /* According to the comments section of the PHP manual page,
+ * it is possible that this function returns an empty string
+ * for some files (e.g. if they don't exist in the magic MIME database)
+ */
+ if (is_string($mime) && preg_match($regexp, $mime, $matches))
+ {
+ $this->file_type = $matches[1];
+ return;
+ }
}
}
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 4a1ce3461..ffa0597b7 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -12,6 +12,7 @@ Bug fixes for 3.1.3
- Fixed a bug (#4886) - :doc:`Database Library <database/inded>` didn't differentiate bind markers inside double-quoted strings in queries.
- Fixed a bug (#4890) - :doc:`XML-RPC Library <libraries/xmlrpc>` didn't work on PHP 7.
+- Fixed a regression (#4887) - :doc:`File Uploading Library <libraries/file_uploading>` triggered fatal errors due to numerous PHP distribution channels (XAMPP and cPanel confirmed) explicitly disabling ext/fileinfo by default.
Version 3.1.2
=============