PHP finfo_file中的DOCX文件类型为application/zip [英] DOCX File type in PHP finfo_file is application/zip

查看:523
本文介绍了PHP finfo_file中的DOCX文件类型为application/zip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在尝试通过 finfo_file 函数验证上传的文件类型.

hello I'm trying to validate an uploaded file type by finfo_file function.

但是,当发送.docx文件时,文件类型为:

But when a .docx file is sent, the file type is:

application/zip

代替:

application/vnd.openxmlformats-officedocument.wordprocessingml.document

如何更改此行为?

推荐答案

据我所知,目前供应商特定的文件类型(vnd.)尚未标准化(通过任何RFC),因此,file_info()并未涵盖这些文件类型. .docx压缩的xml格式,这就是file_info()返回(完全正确).您可以解压缩文件并测试结果的MIME类型,但这将导致文档使用的xml(也完全正确)和其他文件.为了在不同的XML格式之间有所区别,file_info()必须分析其内容,并且必须知道它的外观,所到之处.

As far as I now the vendor specific file types (vnd.) are not standardized (by any RFC) and therefore not covered by file_info(). .docx is a zipped xml-format and thats the reason, why file_info() returns application_zip (what is completely right). You may unzip the file and test the mime-type of the result, but that will lead to xml (what is completely correct too) and other files, that are used by the document. To differ between different XML formats file_info() had to analyze its content and it must know, how it looks, what goes just to far.

这篇关于PHP finfo_file中的DOCX文件类型为application/zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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