0

I see in the thread: How to check file types of uploaded files in PHP? davr suggests the use of:

system("file -bi $uploadedfile")

to check the file type as a safety measure. porneL makes this suggested addition:

system("file -bi -- ".escapeshellarg($uploadedfile))

Could someone explain how executing a potentially hazardous file with the system() function is a safe way to determine a file type?

4

1 回答 1

0

unix 命令“file”没有执行该文件。

来自http://en.wikipedia.org/wiki/File_(command ):

file 是一个标准的 Unix 程序,用于使用幻数识别计算机文件中包含的数据类型。

这里建议检查文件类型的相同方法: http ://www.php.net/manual/en/function.mime-content-type.php#91646

您还可以在这里查看参数 -bi 的含义:http: //linux.about.com/library/cmd/blcmdl1_file.htm

-b 不要将文件名添加到输出行(简要模式)。

-i 使 file 命令输出 mime 类型的字符串,而不是更传统的人类可读的字符串。因此它可能会说text/plain; charset=us-ascii'' rather thanASCII 文本''。为了使此选项起作用,file 更改了它处理命令本身识别的文件的方式(例如许多文本文件类型、目录等),并使用magic'' file. (See下面的替代 FILES'' 部分)。

于 2012-08-09T02:13:51.900 回答