本文整理汇总了PHP中CFileHelper::getExtensionByMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP CFileHelper::getExtensionByMimeType方法的具体用法?PHP CFileHelper::getExtensionByMimeType怎么用?PHP CFileHelper::getExtensionByMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFileHelper
的用法示例。
在下文中一共展示了CFileHelper::getExtensionByMimeType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getExtensionByMimeType
/**
* Determines the file extension name based on a given MIME type, or a file path.
*
* This method will use a local map between MIME type and extension name.
*
* @param string $file The file name or mime type
* @param string $magicFile The path of the file that contains all available extension information.
* If this is not set, the default 'system.utils.fileExtensions' file will be used.
*
* @return string|null The extension name. Null is returned if the extension cannot be determined.
*/
public static function getExtensionByMimeType($file, $magicFile = null)
{
static $mimeTypes, $customMimeTypes = array();
if ($magicFile === null && $mimeTypes === null) {
$mimeTypes = (require \Yii::getPathOfAlias('system.utils.fileExtensions') . '.php');
} else {
if ($magicFile !== null && !isset($customMimeTypes[$magicFile])) {
$customMimeTypes[$magicFile] = (require $magicFile);
}
}
// See if $file is actually a MIME type
$mime = strtolower($file);
if ($magicFile === null && isset($mimeTypes[$mime])) {
return $mimeTypes[$mime];
} else {
if ($magicFile !== null && isset($customMimeTypes[$magicFile][$mime])) {
return $customMimeTypes[$magicFile][$mime];
}
}
return parent::getExtensionByMimeType($file, $magicFile);
}