clarkk clarkk - 3 months ago 7
Linux Question

get mimetype of file as a string (imap_fetchbody)

You can do this if the file is a file in the filesystem:

shell_exec("file -bi $file")


But how can you do it if the file is a string (not yet saved as a file)?

The string/file is extracted from an email with
imap_fetchbody()


edit



$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";


both
$finfo->buffer()
and
$finfo->file()
returns
text/plain; charset=us-ascii
even if its PDF, PNG etc.?

Answer