简体   繁体   中英

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

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

$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?

There is an alternative: Use finfo on both Linux and Windows.

By the way: You have a shell command injection vulnerability. The filename is not escaped - thats what functions like escapeshellargs() are for. Always use them!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM