Is there any way to find the exact file type in php without looking for the letters after the dot(.) ?. Because in that case even if you rename a exe file as png, it will be considered as a png only which is malicious. And some PHP functions like pathinfo()
also returns the value after dot only which is not reliable. Any suggestion or idea on this would be greatly appreciated.
问问题
124 次
4 回答
0
您想要的不是文件扩展名,而是 mime 类型。文件扩展名只不过是一种命名约定,正如您所指出的,它很容易被欺骗。您可以使用该finfo_file
功能来获取此信息。
于 2012-05-24T06:48:51.840 回答
0
上次我检查时,您可以使用 php 函数获取图像的确切文件类型。不确定任意文件。
不可能以 100% 的准确率检测任何文件的文件类型。曾经。您可以制作任意文件,该文件将无法作为检测到的类型打开。
通过检查文件签名(前几个字节),可以高度准确地检测二进制文件的文件类型。如上所述,结果不是 100% 保证的。但是,您必须有一个文件类型签名库才能查找。
检测文本文件的文件类型是可能的,但很难。你能区分不同的语言吗?如果代码可以用一种以上的语言编译怎么办?
于 2012-05-24T06:50:45.877 回答
-2
它是可靠的。扩展名正是最后一个点之后的字母。如果您将 file.exe 重命名为 file.png,它的新扩展名将是 .png 并且将不再是可执行的(在 Windows 中,即在 POSIX 系统中,可执行性不是通过文件扩展名控制的)。
于 2012-05-24T06:47:42.117 回答