[英]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.