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.
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 (
magicormagic.mimein PHP’s directory, most of the time), or the system’s “magic” file (used by thefilecommand on Unix).You can also ask to use a specific “magic” file like this:
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:
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.