[英]create a file (name.extension) by mime type
如何通过mime类型创建文件(name_of_file.file_extension)? 哑剧列表是动态的。
例:
MIME Extension
application/msword | .doc
text/plain | .txt
text/css | .css
我不想使用数组(“mime”=>“扩展名”);
我有mime类型,但我需要文件扩展名。
为了避免使用查找表(至少避免你具有定义一个),可以使用finfo_file
。
echo finfo_file('myfile.jpg', finfo_open(FILEINFO_MIME_TYPE)); // output: image/jpg
如果您使用5.0,则可以尝试使用mime_content_type
(但请记住,这是不推荐使用的,因此如果您正在寻找兼容升级的版本,则可能需要在可能的情况下默认使用新的finfo_file
):
echo mime_content_type('myfile.jpg'); // output: image/jpg
// When possible, it will use upgraded finfo_file, but will default back
// to content_mime_type when necessary
function getMimeType($file){
if (function_exists('finfo_file') && defined('FILEINFO_MIME_TYPE')){
$return_mime = finfo_open(FILEINFO_MIME_TYPE);
return finfo_file($file, $return_mime);
}
return content_mime_type($file);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.