Setting MimeType in PHP

Mon, Jun 22, 2009

Tech Tips

Setting the Mime Type allows you to tell the browser what type of response that it is going to receive. This is useful for returning non html results like file downloads, xml and JSON.

//Setting a XML File Type in PHP
$mtype = "text/xml";
header("Content-Type: " . $mtype);

//Setting a File Download Type in PHP
$mtype = "application/octet-stream";
header("Content-Type: " . $mtype);

//Setting a JSON results type in PHP
$mtype = "application/javascript";
header("Content-Type: " . $mtype);

Here is a list of common mime types:
Javascript – application/javascript
Java – application/x-java-applet
Java – application/x-java-bean
Java – application/x-java-vm
Flash – application/x-shockwave-flash
MP3 – audio/mp3
JPEG – image/jpeg
JPG – image/jpg
GIF – image/gif
PNG – image/png
HTML – text/html
CSS – text/css
Text File – text/plain
XML – text/xml
Video AVI – video/avi
Video Microsoft – video/msvideo
Video QuickTime – video/quicktime
Video DIVX – video/divx
File Download – application/octet-stream

Bookmark and Share
,

Comments are closed.