选择语言 :

 Core_File::mime

返回指定文件类型

$mime = File::mime($file);
string Core_File::mime( string $filename )

参数列表

参数 类型 描述 默认值
$filename string File name or path
返回值
  • string mime type on success
  • FALSE on failure
File: ./core/classes/file.class.php
public static function mime($filename)
{
	// Get the complete path to the file
	$filename = realpath($filename);

	// Get the extension from the filename
	$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));

	if (preg_match('/^(?:jpe?g|png|[gt]if|bmp|swf)$/', $extension) && function_exists('getimagesize'))
	{
		// Use getimagesize() to find the mime type on images
		$file = getimagesize($filename);

		if (isset($file['mime']))
		{
			return $file['mime'];
		}
	}

	if (class_exists('finfo', false))
	{
	    $info = new finfo(defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME);
		if ($info)
		{
			return $info->file($filename);
		}
	}

	if (function_exists('mime_content_type'))
	{
		return mime_content_type($filename);
	}

	if (!empty($extension))
	{
		return File::mime_by_ext($extension);
	}

	return false;
}