How do I tell if someone#39;s faking a filetype? (PHP)(我如何判断是否有人伪造文件类型?(PHP))
问题描述
我正在编写一些程序,允许用户在网络服务器上存储文档和图片,以便以后存储和检索.当用户将文件上传到我的服务器时,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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我如何判断是否有人伪造文件类型?(PHP)
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
