[英]Alternative to finfo(FILEINFO_MIME)->buffer() in Linux command line
Instead of using finfo
on files to retrieve the content-type
you can execute a command in linux 您可以在Linux中执行命令,而
finfo
在文件上使用finfo
来检索content-type
。
if(PHP_OS == 'WINNT'){
$finfo = new finfo(FILEINFO_MIME);
$content_type = $finfo->file($file);
}
else{
$content_type = shell_exec("file -bi $file");
}
If you want to retrieve the content-type
of a file as a string you can do this 如果要以字符串
content-type
检索文件的content-type
,可以执行此操作
$finfo = new finfo(FILEINFO_MIME);
$content_type = $finfo->buffer($data);
But is there an alternative to get the content-type
of the file contents as a string in the linux command line? 但是在Linux命令行中是否还有其他方法可以将文件内容的
content-type
作为字符串获取?
There is an alternative: Use finfo
on both Linux and Windows. 还有一种选择:在Linux和Windows上都使用
finfo
。
By the way: You have a shell command injection vulnerability. 顺便说一句:您有一个shell命令注入漏洞。 The filename is not escaped - thats what functions like escapeshellargs() are for.
文件名不会转义-这就是逃逸shellargs()之类的功能的作用。 Always use them!
始终使用它们!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.