Reputation: 3935
On 2 different AMP servers (one Linux, one Windows), PHP's finfo function is returning a mime type of "video/mp4" for m4a audio files.
$path = '/path/to/some/audio.m4a';
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $path);
print $mime; // video/mp4
I believe this can be controlled with Apache's mime.types file, but after finding the line for "audio/mp4" and adding the m4a extension:
audio/mp4 mp4a m4a
and restarting Apache, it still reports video/mp4.
How can i get finfo to detect the correct (audio) mime type for .m4a audio files?
TYIA.
Upvotes: 4
Views: 1839
Reputation: 1417
The "magic" file used has nothing to do with Apache. It is used as table of file signatures and is, depending on your system, either a "magic" file distributed with PHP (magic
or magic.mime
in PHP's directory, most of the time), or the system's "magic" file (used by the file
command on Unix).
You can also ask to use a specific "magic" file like this:
<?php
$finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic.mgc");
?>
You can either change the system's "magic" file or make your custom one.
The standard file signatures for MPEG-4 audio and video are:
00 00 00 18 66 74 79 70
33 67 70 35 ....ftyp
3gp5
MP4 MPEG-4 video files
00 00 00 18 66 74 79 70
6D 70 34 32 ... ftyp
mp42
M4V MPEG-4 video/QuickTime file
00 00 00 20 66 74 79 70
4D 34 41 20 ... ftyp
M4A
M4A Apple Lossless Audio Codec file
You may want to check first if these are in your "magic" file.
From what I remember, m4a (audio) and m4v (video) may have the same mp4 signature (due to bad encoders), so you can't always differenciate one from the other using the "magic" file. You may then put some PHP code to determine, based on file extension (like Windows does), if it's video or audio mp4.
Upvotes: 4
Reputation: 163232
This has nothing to do with Apache.
The file is local. finfo is going to return what it is going to return. If you believe you need a specific type for a file extension, just return it.
Upvotes: 0