如何获取PHP中的mime类型 [英] How can I get the mime type in PHP

查看:95
本文介绍了如何获取PHP中的mime类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写脚本,我需要正确地获取文件(文件可以是任何类型)的mime类型(我认为某些mime类型可能与其扩展名不同).

正在使用的网络托管公司没有mime_content_type(),并且仍然(不知道他们将在哪一年对其进行修复)承诺修复PECL替代方案.

我还能通过其他什么方式(而且我没有访问shell命令的权限)?

解决方案

$ _ FILES ['file'] ['type']来自上传文件的浏览器,因此您完全不能依赖此值. /p>

查看 finfo_file ,以根据文件识别文件类型内容.该文件的扩展名也不可靠,因为用户可以上传带有mp3扩展名的恶意代码.

I am writing a script and I need to correctly (I think some mime types can be different from their extensions) get the mime types of files (the files can be of any type).

Web hosting company in use does not have mime_content_type() and is still (don't know which year they will be fixing it) promising to fix the PECL alternative.

Which other way can I go about it (and I don;t have access to shell commands)?

解决方案

$_FILES['file']['type'] comes from the browser that uploads the file so you can't rely on this value at all.

Check out finfo_file for identifying file types based on file content. The extension of the file is also unreliable as the user could upload malicious code with an mp3 extension.

这篇关于如何获取PHP中的mime类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆