Home  >  Article  >  Backend Development  >  为什么要用finfo_file 而不是直接用上传数组的type?该如何解决

为什么要用finfo_file 而不是直接用上传数组的type?该如何解决

WBOY
WBOYOriginal
2016-06-13 12:14:41961browse

为什么要用finfo_file 而不是直接用上传数组的type???
最近研究图片上传类;

里面用 finfo_file() 来检测文件mime;  

很是费解: 上传的数组中明明就有type="", 和finfo_file() 的结果是一样的;

请问: 为何多此一举,用finfo_file() 再次检测mime呢?   无论怎么改后缀,数组的type和finfo_file的结果都是相同的;

唯一的解释就是: 黑客可以修改上传文件的数组,感觉不太现实啊. 按照这种道理,是不是所有未经过finfo_file() 检测的都有漏洞?不可能啊.. 


求解释为何要再次使用finfo_file()来对上传的文件MIME再次校正
------解决思路----------------------
注意 finfo_file 只在 php5.3 以上才可用

上传文件的类型是浏览器识别的,同一种文件,不同的浏览器判定的可能不同
finfo_file 用于在服务器端判断,这样就统一了不同浏览器间的差异

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn