Get the correct Mime Types by file extension easily using this useful Javascript class.
To use this helper class the only thing you need to do is just submit the file type you want to know the mime type from:
MimeTea.cup("txt");
This will return "text/plain".
You can also submit a file type containing the dot like:
MimeTea.cup(".txt");
If you want to submit an array of file types, MimeTea also supports it:
MimeTea.cup(
[".txt", ".html", ".css"]
);
Which will return the following Javascript array:
["text/plain", "text/html", "text/css"]
Very useful for application that use the html file input tag where you'll need to specify the accept parameter to contain the correct mime type.
Enjoy. Comments are welcome. Rox