如何识别文件的文件类型? [英] How to identify the file type of a file?

查看:161
本文介绍了如何识别文件的文件类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何识别文件的确切文件类型?为了更好地理解,我提供了更多详细信息:

How to identify the exact file type of a file? For better understanding I am giving some more details:

例如,如果我有一个名为"example.exe"的文件,则可以轻松地识别出它是Windows可执行文件(通过查看扩展名.exe).但是,如果删除扩展名(.exe),则无法看到文件类型.

For example if I have a file named as "example.exe" then I can easily recognize that it's a windows executable file (by seeing the extension .exe). But if I remove the extension (.exe) then by seeing I am not able to identify the type of the file.

那我现在如何识别文件类型?

Then now how can I identify the file type?

((请使用c/c ++,java,python或php建议答案)(用于网络上传)

(Please suggest your answers using c/c++, java, python or php (For web uploads))

谢谢

推荐答案

没有精确文件类型"之类的东西.二进制数据是二进制数据.

There's no such thing as "exact file type". Binary data is binary data.

如果您在类似POSIX的系统上运行,则可以使用file命令来猜测文件类型.我认为这不会给您提供MIME类型.

If you're running on a POSIX-like system, you can use the file command to guess the file type. I don't think this gives you a MIME type.

如果您的服务器运行的是Apache,则可以使用mod_mime_magic进行猜测.

If your server is running Apache, then you can use mod_mime_magic to make a guess.

如果您使用的是PHP,则可以安装 fileinfo 扩展名.

If you're using PHP, you can install the fileinfo extension.

这篇关于如何识别文件的文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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