PHP Headers and Popular Mime Types
Like my Create a Basic Web Service Using PHP, MySQL, XML, and JSON illustrates, even though a file's extension ends in PHP, you can still tell the browser that you're outputting a different content type. Here are a few of the more popular content types used on the internet.
Atom
header('Content-Type: application/atom+xml');
CSS
header('Content-Type: text/css');
Javascript
header('Content-Type: text/javascript');
JPEG Image
header('Content-Type: image/jpeg');
JSON
header('Content-Type: application/json');
header('Content-Type: application/pdf');
RSS
header('Content-Type: application/rss+xml; charset=ISO-8859-1');
Text (Plain)
header('Content-Type: text/plain');
XML
header('Content-Type: text/xml');
Just because a file ends in .PHP doesn't mean it responds with XHTML -- respond however you'd like!
Great list of mime types.
Perhaps I’d just be careful about the charset at the RSS example. People could add it blindly and suddenly accented characters would stop working if the rest of the site is using other encodings, like utf-8.
Interesting list. Nothing new, but still nice. BTW Javascript and XML should be application, text is obsolete.
@Matěj Grabovský: Interesting. Can you share your resource for knowing that?
Thank you for sharing your list
Please check below link complete list of mime types
http://webdesign.about.com/od/multimedia/a/mime-types-by-file-extension.htm
Now, I have only question related to your awesome site.
Question: How your site is working fast? When I click on any link, page loads are very fast and easily.
Will you give me answer?
@David Walsh: Well, especially Wikipedia, RFCs (concretely RFC3023) and this thing.
Thank you for sharing Matěj!
You’re welcome, sir!
BTW, It is common to prefix experimental mime types with ‘x-‘ (e.g. application/x-json)
Very usefull stuff, I suggest you ad this one too (exe, zip, rar…)
BTW, 7 comments, since may 7th… and it’s 7 a.m. here in Morocco
Thanks a lot for this information.
Content-Type or Content-type ?
Have been using just the java, css and htmls. Will do with the rest later.
Thanks for the list David.
Pleasure reading.
;)
Perfect list! Just what I was looking for. Thanks, Mr. Walsh :-)
nodeset[0];
$i = $r->new_child(“item”);
$i->new_child(“title”, $head);
$i->new_child(“link”, $link);
$i->new_child(“description”, $comment);
$out = domxml_dumpmem($doc);
$file = $arch . “.xml”;
$f = fopen($file, ‘w’);
fputs($f, $out);
fclose($f);
echo $out;
?>
Really nice, that’s exactly what I was looking for!
Thanks a lot David, for another great tutorial.