Q:

Sending most correct mimetype

I have a list of extension to mimetype in a INI file. However some extensions have multiple mimetypes, for example;
midi[] = "application/x-midi"
midi[] = "audio/midi"
midi[] = "audio/x-mid"
midi[] = "audio/x-midi"
midi[] = "music/crescendo"
midi[] = "x-music/x-midi"
6 (possible) mimetypes for 1 extension. Whats common practice to determine the correct mimetype? (e.g. i need to set a HTTP content-type header).
I know its not ideal; determining mimetypes based on extension.. but i need consistent (cross-server) results (e.g. fileinfo extension in PHP is making terrible guesses*).
* Some fileinfo results for example;

js - text/plain
css - text/c-h

A:

What i final came up with is the following;
First i use "FileInfo" for 100% (known) matches (e.g. gif, jpeg, png) because i do want to rely on "fingerprint" detection for certain files.
If above fails, i fallback on a "extension 2 mimetype" map; based on docs/conf/mime.types (I filtered all common used files; e.g. image, audio, video, web, text)
If still no match found, i use "FileInfo" again; allowing any result.
At this point, if the mimetype is still not set i return "application/octet-stream" hardcoded.

