Skip to content

Commit

Permalink
[ci skip] Fix #4887
Browse files Browse the repository at this point in the history
  • Loading branch information
narfbg committed Oct 31, 2016
1 parent 6b5464c commit 7cc0823
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
36 changes: 23 additions & 13 deletions system/libraries/Upload.php
Expand Up @@ -1218,21 +1218,31 @@ protected function _file_mime_type($file)
// 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;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelog.rst
Expand Up @@ -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
=============
Expand Down

0 comments on commit 7cc0823

Please sign in to comment.