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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:44:43  来源:igfitidea点击:

PHP: File extension to MIME type?

phpfilemime

提问by FtDRbwLXw6

Possible Duplicate:
How do I determine the extension(s) associated with a MIME type in PHP?

可能的重复:
如何确定与 PHP 中的 MIME 类型关联的扩展名?

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

try thisto get info about which extension is which mime type, but of course please be aware that this won't be very accurate (e.g. possible gif file on png extension..)

尝试此操作以获取有关哪个扩展名是哪种 mime 类型的信息,但当然请注意,这不会非常准确(例如,png 扩展名上可能的 gif 文件..)

回答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

http://www.php.net/manual/en/ref.fileinfo.php

http://www.php.net/manual/en/ref.fileinfo.php