问题描述
我正在编写一些程序,允许用户在网络服务器上存储文档和图片,以便以后存储和检索.当用户将文件上传到我的服务器时,PHP 会根据扩展名告诉我它是什么文件类型.但是,我担心用户可以将 zip 文件重命名为 somezipfile.png 并存储它,从而在我的服务器上保留一个 zip 文件.有什么合理的方法可以打开上传的文件并检查"它是否真的属于上述文件类型?
I'm programming something that allows users to store documents and pictures on a webserver, to be stored and retrieved later. When users upload files to my server, PHP tells me what filetype it is based on the extension. However, I'm afraid that users could rename a zip file as somezipfile.png and store it, thus keeping a zip file on my server. Is there any reasonable way to open an uploaded file and "check" to see if it truly is of the said filetype?
推荐答案
幻数.如果您可以读取二进制文件的前几个字节,您就可以知道它是什么类型的文件.
Magic number. If you can read first few bytes of a binary file you can know what kind of file it is.
这篇关于我如何判断是否有人伪造文件类型?(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)