且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 PHP 中检查上传文件的文件类型?

更新时间:2023-02-08 18:45:00

看一看 mime_content_type文件信息.这些是内置的 PHP 命令,用于通过查看文件的内容来确定文件的类型.还检查了上面两页的评论,还有一些其他的好建议.

Take a look at mime_content_type or Fileinfo. These are built-in PHP commands for determining the type of a file by looking at the contents of the file. Also check the comments on the above two pages, there are some other good suggestions.

就我个人而言,使用本质上是 system("file -bi $uploadedfile") 的东西我很幸运,但我不确定这是否是***的方法.

Personally I've had good luck using something that's essentially system("file -bi $uploadedfile"), but I'm not sure if that's the best method.