<?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>Under Development :: Life in the Virtual World &#187; Safari</title>
	<atom:link href="http://underdevelopment.maravillaclan.net/category/safari/feed/" rel="self" type="application/rss+xml" />
	<link>http://underdevelopment.maravillaclan.net</link>
	<description>Learning to do it a little better</description>
	<lastBuildDate>Wed, 09 Dec 2009 12:23:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP Force Download :: Fixing Safari Download Header Issues</title>
		<link>http://underdevelopment.maravillaclan.net/2007/10/26/php-force-download-fixing-safari-download-header-issues/</link>
		<comments>http://underdevelopment.maravillaclan.net/2007/10/26/php-force-download-fixing-safari-download-header-issues/#comments</comments>
		<pubDate>Fri, 26 Oct 2007 03:42:35 +0000</pubDate>
		<dc:creator>Bong-Bong</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://underdevelopment.maravillaclan.net/?p=5</guid>
		<description><![CDATA[Problem:
We&#8217;d got this client requesting a download script written in PHP. The Script should be able to run in Mozilla Firefox, MS IE, and Safari. Sounds simple enough right? I mean this could simply be done by just sending the following headers:
&#8212;
header(&#8220;Pragma: public&#8221;);
header(&#8220;Expires: 0&#8243;);
header(&#8220;Cache-Control: must-revalidate, post-check=0, pre-check=0&#8243;);
header(&#8220;Cache-Control: private&#8221;,false);
header(&#8220;Content-Transfer-Encoding: binary&#8221;);
header(&#8220;Content-Type: video/x-ms-wmv&#8221;);
header(&#8220;Content-Length: &#8220;.@filesize($filepath));
header(&#8220;Content-Disposition: attachment; filename=\&#8221;".$filename.&#8220;\&#8221;;&#8221;);
&#8212;
We&#8217;ve been using [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong><br />
We&#8217;d got this client requesting a download script written in PHP. The Script should be able to run in Mozilla Firefox, MS IE, and Safari. Sounds simple enough right? I mean this could simply be done by just sending the following headers:<br />
&#8212;<br />
<fontcolor="#0000ff"><font color="#0000ff">header</font><span>(</span><font color="#ff0000">&#8220;Pragma: public&#8221;</font><span>);</span><br />
<font color="#0000ff">header</font><span>(</span><font color="#ff0000">&#8220;Expires: 0&#8243;</font><span>);</span><br />
<font color="#0000ff">header</font><span>(</span><font color="#ff0000">&#8220;Cache-Control: must-revalidate, post-check=0, pre-check=0&#8243;</font><span>);</span><br />
<font color="#0000ff">header</font><span>(</span><font color="#ff0000">&#8220;Cache-Control: private&#8221;</font><span>,</span><font color="#0000ff">false</font><span>);</span><br />
<font color="#0000ff">header</font><span>(</span><font color="#ff0000">&#8220;Content-Transfer-Encoding: binary&#8221;</font><span>);</span><br />
<font color="#0000ff">header</font><span>(</span><font color="#ff0000">&#8220;Content-Type: video/x-ms-wmv&#8221;</font><span>);</span><br />
<font color="#0000ff">header</font><span>(</span><font color="#ff0000">&#8220;Content-Length: &#8220;</font><span>.@</span><font color="#0000ff">filesize</font><span>($filepath));</span><br />
<font color="#0000ff">header</font><span>(</span><font color="#ff0000">&#8220;Content-Disposition: attachment; filename=\&#8221;"</font><span>.$filename.</span><font color="#ff0000">&#8220;\&#8221;;&#8221;</font><span>);</span><br />
&#8212;<br />
We&#8217;ve been using this header to force browser to download contents since day one.  We thought nothing was wrong with it. That&#8217;s before we tested it with Safari. For some reason Safari just displays a blank white page. No error messages no nothing.</fontcolor="#0000ff"></p>
<p><strong>Solution:</strong><br />
<span id="more-5"></span></p>
<p>Apparently this is caused by Safari not being able to identify what file it is accessing. It doesn&#8217;t know how to deal with &#8220;video/x-ms-wmv&#8221; with is the mime-type for *.wmv files. The mime-type it recognizes as downloadable would be &#8220;application/octet-stream&#8221;. So by changing the header being passed you would be able to force Safari to download the contents. Of course you&#8217;ll still need to attach the contents after sending the headers. The resulting headers will then be:</p>
<p>&#8212;<br />
<font color="#0000ff">header</font>(<font color="#ff0000">&#8216;Expires: 0&#8242;</font>);<br />
<font color="#0000ff">header</font>(<font color="#ff0000">&#8216;Last-Modified: &#8216;</font> .    <font color="#0000ff">gmdate </font>(<font color="#ff0000">&#8216;D, d M Y H:i:s&#8217;</font>, <font color="#0000ff">filemtime </font>($filepath)) . <font color="#ff0000">&#8216; GMT&#8217;</font>);<br />
<font color="#0000ff">header</font>(<font color="#ff0000">&#8216;Pragma: public&#8217;</font>);<br />
<font color="#0000ff">header</font>(<font color="#ff0000">&#8216;Cache-Control: must-revalidate, post-check=0, pre-check=0&#8242;</font>);<br />
<font color="#0000ff">header</font>(<font color="#ff0000">&#8216;Accept-Ranges: bytes&#8217;</font>);<br />
<font color="#0000ff">header</font>(<font color="#ff0000">&#8216;Content-Length: &#8216;</font> . @<font color="#0000ff">filesize</font>($filepath));<br />
<font color="#0000ff">header</font>(<font color="#ff0000">&#8216;Content-Type: Application/octet-stream&#8217;</font>);<br />
<font color="#0000ff">header</font>(<font color="#ff0000">&#8216;Content-Disposition: attachment; filename=&#8221;&#8216; </font>. $filename. <font color="#ff0000">&#8216;&#8221;&#8216;</font>);<br />
<font color="#0000ff">header</font>(<font color="#ff0000">&#8216;Connection: close&#8217;</font>);<br />
&#8212;</p>
<p><strong>Source:</strong><br />
<a href="http://indiegamer.com/archives/t-1953.html" target="_blank">Dexterity Software Forums &#8211; Hiding download path in PHP </a></p>
<p><strong>Note:</strong><br />
I don&#8217;t know why Safari developers haven&#8217;t addressed this issue yet as not all web developers comply with their obsolete method. There are numerous post in the web stating that Safari users are unable to download anything from the web. This is probably cause by URL masking scripts as developers would like to hide the path to their files. Content-type should be indicative and specific to its content. But for the meantime these headers will serve its purpose until Safari and other browsers recognize more mime-types.</p>
]]></content:encoded>
			<wfw:commentRss>http://underdevelopment.maravillaclan.net/2007/10/26/php-force-download-fixing-safari-download-header-issues/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
