I know of the UNIX command file
to detect the mime type of a file, which I can execute via PHP (like here):
$content_type = exec("file -bi " . escapeshellarg($filepath));
And I am also aware of
$fi = new finfo();
echo $fi->file($filename, FILEINFO_MIME_TYPE) . PHP_EOL;
and
echo mime_content_type($filename) . PHP_EOL;
Both PHP built-in solutions produce the same output. However, the Linux file
command knows some formats more.
AMR audio files were reported as application/octet-stream
with all three methods. Then I added the file magic to the database of the file
command:
$ cat /etc/magic
0 string #!AMR\n Adaptive Multi-Rate Audio Codec
!:mime audio/amr
$ file -bi test115.amr
audio/amr; charset=binary
However, PHP still reports application/octet-stream
.
I thought the PHP-builtin and file
use the same database somehow. How can I train PHP to know the MIME type of an AMR file?