mirror of
https://github.com/yiisoft/yii.git
synced 2026-03-15 12:36:54 +01:00
Fixes #1393: CFileHelper::getMimeTypeByExtension() used to treat $magicFile parameter as array with MIME-types, but not the string containing path of the file with MIME-types as it should be.
This commit is contained in:
@@ -213,7 +213,9 @@ class CFileHelper
|
||||
* @param string $file the file name.
|
||||
* @param string $magicFile name of a magic database file, usually something like /path/to/magic.mime.
|
||||
* This will be passed as the second parameter to {@link http://php.net/manual/en/function.finfo-open.php finfo_open}.
|
||||
* This parameter has been available since version 1.1.3.
|
||||
* Magic file format described in {@link http://linux.die.net/man/5/magic man 5 magic}, note that this file does not
|
||||
* contain a standard PHP array as you might suppose. Specified magic file will be used only when fileinfo
|
||||
* PHP extension is available. This parameter has been available since version 1.1.3.
|
||||
* @param boolean $checkExtension whether to check the file extension in case the MIME type cannot be determined
|
||||
* based on finfo and mime_content_type. Defaults to true. This parameter has been available since version 1.1.4.
|
||||
* @return string the MIME type. Null is returned if the MIME type cannot be determined.
|
||||
@@ -246,14 +248,18 @@ class CFileHelper
|
||||
*/
|
||||
public static function getMimeTypeByExtension($file,$magicFile=null)
|
||||
{
|
||||
static $extensions;
|
||||
if($extensions===null)
|
||||
$extensions=$magicFile===null ? require(Yii::getPathOfAlias('system.utils.mimeTypes').'.php') : $magicFile;
|
||||
static $extensions, $customExtensions;
|
||||
if($magicFile===null && $extensions===null)
|
||||
$extensions=require(Yii::$customExtensions('system.utils.mimeTypes').'.php');
|
||||
else if($magicFile!==null && $customExtensions===null)
|
||||
$customExtensions=require($magicFile);
|
||||
if(($ext=pathinfo($file, PATHINFO_EXTENSION))!=='')
|
||||
{
|
||||
$ext=strtolower($ext);
|
||||
if(isset($extensions[$ext]))
|
||||
return $extensions[$ext];
|
||||
else if(isset($customExtensions[$ext]))
|
||||
return $customExtensions[$ext];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user