加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

如何读取PHP上传文件的标题?

发布时间:2020-05-25 08:58:42 所属栏目:PHP 来源:互联网
导读:我们可以在 PHP中读取文件的头信息来确定上传的文件类型吗? 我不想依赖$_FILES [‘control_name_from_client’] [‘type’].我们知道这个属性通过读取上传文件的扩展名来确定文件类型. 如果用户重命名,比如test.jpg – TEST.XLS.在这种情况下,$_FILES [‘con

我们可以在 PHP中读取文件的头信息来确定上传的文件类型吗?

我不想依赖$_FILES [‘control_name_from_client’] [‘type’].我们知道这个属性通过读取上传文件的扩展名来确定文件类型.

如果用户重命名,比如test.jpg – > TEST.XLS.在这种情况下,$_FILES [‘control_name_from_client’] [‘type’]将显示类型为application / vnd.ms-excel而不是image / jpeg.如果必须执行代码来读取XLS文件以获取某些处理的数据,这很自然会产生问题.

有什么建议吗?

尝试 finfo_file().你必须通过文件路径调用它.例:
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo,$_FILES['control_name_from_client']['tmp_name']);
finfo_close($finfo);

您需要Fileinfo扩展.正如PHP手册所说:

The functions in this module try to guess the content type and encoding of a file by looking for certain magic byte sequences at specific positions within the file. While this is not a bullet proof approach the heuristics used do a very good job.

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读