简体   繁体   English

检查文件mime-type是否与php中的扩展名匹配

[英]check if a files mime-type matches it's extension in php

Is there any way to check that a files mime-type matches it's extension in php ? 有什么方法可以检查文件mime-type是否匹配它在php中的扩展名?

Thanks, Adam 谢谢亚当

See here: http://www.php.net/manual/en/function.finfo-file.php . 参见此处: http : //www.php.net/manual/zh/function.finfo-file.php This function allows you to detect the file's mime-type. 使用此功能可以检测文件的mime类型。

If you have a list of known mime types with corresponding extensions, using the mime_content_type function and looking up the extension in an array is simple. 如果您具有已知的mime类型列表以及相应的扩展名,则使用mime_content_type函数并在数组中查找扩展名很简单。 There are problems, however; 但是有问题。 a comprehensive list would be large and likely become outdated fairly quickly, and sniffing mime types is generally considered a difficult problem with inaccurate solutions . 一个完整的列表会很大,并且可能很快就会过时,并且嗅探哑剧类型通常被认为是解决方案不准确的难题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM