<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>code-diesel &#187; mime</title>
	<atom:link href="http://www.codediesel.com/tag/mime/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Pushing xpi mime content from php</title>
		<link>http://www.codediesel.com/php/sending-xpi-mime-content-from-php/</link>
		<comments>http://www.codediesel.com/php/sending-xpi-mime-content-from-php/#comments</comments>
		<pubDate>Fri, 15 May 2009 04:01:49 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[mime]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=880</guid>
		<description><![CDATA[A couple of days back I created a Firefox toolbar for my blog as an experiment in learning XUL. Once installed on my blog I wanted Firefox to recognize it as an addon and install it rather than displaying a &#8216;save/open&#8217; dialog. For that I needed to add the following directive to the servers .htaccess [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days back I created a Firefox toolbar for my blog as an experiment in learning XUL. Once installed on my blog I wanted Firefox to recognize it as an addon and install it rather than displaying a &#8216;save/open&#8217; dialog. For that I needed to add the following directive to the servers .htaccess file.<br />
<span id="more-880"></span></p>

<div class="wp_codebox"><table><tr id="p8803"><td class="code" id="p880code3"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">AddType</span> application/x-xpinstall .xpi</pre></td></tr></table></div>

<p>But the problem was that my server (godaddy) for some mysterious reasons was not recognizing the above directive. Searching around I found that godaddy has some restrictions on the various htaccess directives (yuck!). After fiddling for some time I finally had to try another solution. </p>
<p>What the Apache &#8216;AddType&#8217; directive does is that it maps the given filename extension onto the specified MIME content type, so that the browser can understand what it is supposed to do with the content. If we could replicate that in PHP than we are good. A possible solution that worked for me is shown below. You can also use the idea for other MIME types.</p>

<div class="wp_codebox"><table><tr id="p8804"><td class="code" id="p880code4"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/* File we want to send to the browser */</span>
<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;codediesel.xpi&quot;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * The following header is required for browsers that do not
 * recognize the xpi extension. i.e all browsers other than Firefox.
 * This will display the familiar 'save/open' dialog if the xpi
 * extension is not supported.
 */</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Disposition: filename=<span style="color: #006699; font-weight: bold;">{$filename}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/* Tell the browser that the content that is coming is an xpinstall */</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: application/x-xpinstall'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/* Also send the content length */</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Length: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #009933; font-style: italic;">/* readfile reads the file content and echos it to the output */</span>
<span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Of course if the filesize is large the <em>readfile</em> function could possibly incur a performance hit. But for small files it works good.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/php/sending-xpi-mime-content-from-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

