获取文件的mime类型作为字符串(imap_fetchbody)


get mimetype of file as a string (imap_fetchbody)

如果该文件是文件系统中的一个文件,则可以这样做:

shell_exec("file -bi $file")

但是如果文件是字符串(尚未保存为文件),您如何做到这一点?

字符串/文件是从带有imap_fetchbody()

的电子邮件中提取的。<标题>编辑
$body = imap_fetchbody($this->stream, $this->msgno, $section);
$finfo = new finfo(FILEINFO_MIME);
echo $finfo->buffer($body) . "'n";
$file = Init::$dynamic['data_path'].$this->msgno.'_'.$part->dparameters[0]->value;
imap_savebody($this->stream, $file, $this->msgno, $section);
echo $finfo->file($file) . "'n";

$finfo->buffer()$finfo->file()返回text/plain; charset=us-ascii,即使它的PDF, PNG等?

finfo_buffer