August 19, 2003

Mime Types

Fusium has put together a good listing of mime type associations. <cfscript>     mime=structNew();     mime.ai="application.postscript";     mime.asc="text/plain";     mime.au="audio/basic";     mime.avi="video/avi";     mime.bmp="image/bmp";     mime.cfm="text/plain";     mime.cpt="application/mac-compactpro";     mime.csv="text/plain";     mime.dbm="text/plain";     mime.doc="application/msword";     mime.exe="application/octet-stream";     mime.gif="image/gif";     mime.html="text/html";     mime.htm="text/html";     mime.jpeg="image/jpeg";     mime.jpg="image/jpeg";     mime.mid="audio/midi";     mime.mov="video/quicktime";     mime.mp2="audio/mpeg";     mime.mp3="audio/mpeg";     mime.mpeg="video/mpeg";     mime.mpg="video/mpeg";     mime.pdf="application/pdf";     mime.png="image/pdf";     mime.ppt="vnd.ms-powerpoint";     mime.ps="application/postscript";     mime.ram="audio/x-pn-realaudio";     mime.rpm="audio/x-pn-realaudio-plugin";     mime.rtf="application/rtf";     mime.sit="application.stuffit";     mime.snd="audio/basic";     mime.swf="application/x-shockwave-flash";     mime.tar="application/x-tar";     mime.tiff="image/tiff";     mime.tif="image/tiff";     mime.txt="text/plain";     mime.wav="audio/wav";     mime.wrl="model/vrml";     mime.xbm="image/x-xbitmap";     mime.xpm="image/x-xpixmap";     mime.zip="application/zip";     mime._default="application/octet-stream"; </cfscript>
Post Info

Tagged As Coding, Reference

Comments are Open (13)

Posted at 07:43 AM

Comments

Anne van Kesteren

Who that are a lot of mime-types, he forgot application/xhtml+xml, which you should use too :)!

Tony

That's a good point. That is not listed. But looking over the function, it's not possible. This is for determining mime types of file extensions.

So what would you determine the mime type of .htm? That could be text/html or application/xhtml+xml.

I'd rather err on text/html.

But you are right. There is no easy way (yet) to check for application/xhtml+xml like that.

Anne van Kesteren

It's not dependent on the file extension it is dependent on your source code. XHTML __should__ be send as application/xhtml+xml. More info: http://www.goer.org/Markup/TheXPhiles/

Tony

Oh, I agree with that. But _this_ code extension is builidng a structure within ColdFusion to recognize the mime type from the file extension. That's where the probable confusion comes in.

I found the list useful because if I need the mime type, I always have to go double check it. I haven't memorized that a flash file (swf) is "application/x-shockwave-flash".

And I have other issues with sending the "correct" mime type to the browser. See http://www.simiandesign.com/blog-fu/2003/05/001578.cfm to follow my whole process. I sort of drew my line in the sand over this issue, because I DO NOT want to browser sniff.

Anne van Kesteren

You could do it really easy in .htaccess, _without_ browser sniffling. I do it in PHP _without_ broser sniffling. Maybe it's also possible in ColdFusion. If think it is. I check if the browser has an accept-header for application/xhtml+xml if it has one I send it as XML if it doesn't (IE) it will get HTML.

Tony

Really? I had never thought of that way.

I didn't even know you could do it in .htaccess. I'd love to see an example of that.

How do you do it in PHP? Can you post your code example of that? You ought to post about that Anne. That sounds like it doesn't break my "line in the sand", and does things properly.

Anne van Kesteren

PHP:

.htaccess:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml\s*;\s*q=0
RewriteCond %{REQUEST_URI} \.html$
RewriteCond %{THE_REQUEST} HTTP/1\.1
RewriteRule .* - [T=application/xhtml+xml]

I hope you convert and send Evan Goer an e-mail. More people should do this.

Anne van Kesteren

Again PHP, but without the stripped php element:

if(stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")){
header("Content-type:application/xhtml+xml");
}else{
header("Content-type: text/html");
}

Succes!

Tony

Very nice.

That is most excellent. I will have to look into doing this in ColdFusion, as my hosted server doesn't do the .htaccess.

But very slick. Thanks a ton Anne.

NethaZile

Excellent inputs from all of you. I've got a question that after scouring, probing and asking about for sometime now, I have yet to get a valid answer for.

When adding a new MIME type so that a particular file type extension is recognized, WHAT is the determining factor for which MIME type to choose. For example, you have a .dwg file (CAD drawing) with the following choices of MIME types:

application/acad
image/vnd.dwg
image/x-dwg

Certainly you would not want to use all three, but again what do I use to determine which of the three I should use?

Peace,
NZ

Tony

That's a good question. I don't know off-hand. I'll have to think about that.

urugn

What about application/java-archive for jar files? Coldfusion returns application/x-zip-compression mime type for .jar files download instead of application/java-archive. i need it to do it right for j2me deployment.

urugn

Actually its application/x-zip-compressed not application/x-zip-compression. I have tried to add the .jar content type inside the c:\coldfusionmx\runtime\lib\mime.types file but still it returns application/x-zip-compressed for jar files. surely in php and iis setting mime types is fairly easy. but i sure love cfml.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Search
Comments on this post
Categories
Info
Tony Stephens
Copyright © 1995-2005
Site Version:
10
Licensed:
Creative Commons
Validate:
XHTML, CSS, 508, RSS
Subscribe
Blog-Fu, Link-Fu