public static getMimeTypeByExtension ( string $file, string $magicFile = null ) : string | ||
$file | string | the file name. |
$magicFile | string | the path (or alias) of the file that contains all available MIME type information. If this is not set, the file specified by [[mimeMagicFile]] will be used. |
return | string | the MIME type. Null is returned if the MIME type cannot be determined. |
public static function getMimeTypeByExtension($file, $magicFile = null)
{
$mimeTypes = static::loadMimeTypes($magicFile);
if (($ext = pathinfo($file, PATHINFO_EXTENSION)) !== '') {
$ext = strtolower($ext);
if (isset($mimeTypes[$ext])) {
return $mimeTypes[$ext];
}
}
return null;
}