PHP:MIME 类型的文件扩展名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11544609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP: File extension to MIME type?
提问by FtDRbwLXw6
Possible Duplicate:
How do I determine the extension(s) associated with a MIME type in PHP?
I'm aware of how to get the MIME type of a given file, but is there a way to do it given only an extension?
我知道如何获取给定文件的 MIME 类型,但是有没有办法只给一个扩展名?
Example input:
示例输入:
jpg
Example output:
示例输出:
image/jpeg
采纳答案by Jerzy Zawadzki
回答by Ross Smith II
The most elegant solution I've seen for Apache environments is http://www.php.net/manual/en/function.mime-content-type.php#107798
我见过的最优雅的 Apache 环境解决方案是http://www.php.net/manual/en/function.mime-content-type.php#107798
回答by Tchoupi
I don't have the Fileinfo extension installed, but from PHP documentation, it seems like Fileinfo might give you that information, which was previously given by the deprecated function mime_content_type()
我没有安装 Fileinfo 扩展,但从 PHP 文档来看,似乎 Fileinfo 可能会为您提供该信息,该信息以前由已弃用的函数提供 mime_content_type()
http://www.php.net/manual/en/function.mime-content-type.php
http://www.php.net/manual/en/function.mime-content-type.php

