views:

40

answers:

2

Hi all,

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
+1  A: 

At the end of the day the best you have is the file extension.

For definite list, locate this in the apache source tree: docs/conf/mime.types

zaf
I already figured that out ;-) The point is i have multiple possible mimetypes to choose from... and im not sure which one to pick.Edit;Hm.. "definite list" as in 1 extenstion pointed to 1 mimetype?
Roland Franssen
No, you can have multiple extensions going to 1 mimetype. For example exe, dll, com, bat and msi map to application/x-msdownload I wish I could paste the list here but its like well over 1000 entries!
zaf
I looked at the list.. and its indeed definite (e.g. 1 mimetype per extension.. however youre right about how they formatted it; multiple extensions mapped to 1 mimetype).. im going to stick with this however, thanks!
Roland Franssen
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.

Roland Franssen