<?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>I Accept Cookies &#187; apache</title>
	<atom:link href="http://www.iacceptcookies.com/category/web-development/apache/feed" rel="self" type="application/rss+xml" />
	<link>http://www.iacceptcookies.com</link>
	<description>James Larkin's rambling blog without the rambling</description>
	<lastBuildDate>Fri, 29 Jan 2010 06:28:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>how can I have a file automatically download</title>
		<link>http://www.iacceptcookies.com/web-development/apache/how-can-i-have-a-file-automatically-download</link>
		<comments>http://www.iacceptcookies.com/web-development/apache/how-can-i-have-a-file-automatically-download#comments</comments>
		<pubDate>Fri, 07 Sep 2007 09:45:05 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[apache]]></category>

		<guid isPermaLink="false">http://www.iacceptcookies.com/web-development/apache/how-can-i-have-a-file-automatically-download</guid>
		<description><![CDATA[ok the title is possibley a little bit misleading &#8230; the other day a question on boards was how can I have a file automagically popup the save as dialogue when you click on it &#8230; other peoples responses were to add in some text saying right click on the file and choose save as [...]]]></description>
			<content:encoded><![CDATA[<p>ok the title is possibley a little bit misleading &#8230; the other day a question on boards was how can I have a file automagically popup the save as dialogue when you click on it &#8230; other peoples responses were to add in some text saying right click on the file and choose save as &#8230; ridiculous but even I&#8217;ve done it in the past  &#8230; distant past <img src='http://www.iacceptcookies.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>My first solution was to write a php script and have that alter the headers of the file &#8230; the code is pretty simple</p>
<blockquote><p> &lt;?php<br />
header(&#8216;Content-type: text/plain&#8217;);<br />
header(&#8216;Content-Disposition: attachment;filename=&#8221;myfile.txt&#8221;&#8216;);<br />
readfile(&#8216;myfile.txt&#8217;);<br />
?&gt;</p></blockquote>
<p>They weren&#8217; too thrilled with that option and were wondering if there&#8217;s some way to do it with apache &#8230; to be honest I hadn&#8217;t a clue and I ended up doing a bit of research &#8230;</p>
<p>It would seem that adding in the following code</p>
<blockquote><p> &lt;filesmatch &#8220;\.(?i:txt)$&#8221;&gt;<br />
ForceType plain/txt<br />
Header set Content-Disposition attachment<br />
&lt;/filesmatch?&gt;</p></blockquote>
<p>will nicely alter the headers of the file without you having to go off writing and scripts &#8230; If you&#8217;ve any experience with regexp then you&#8217;ll see what the filesmatch piece is doing &#8220;\.(?i:txt)$&#8221; matching a . case insensitive txt match at the end ofthe filename</p>
<p>now you&#8217;ve two options you can include this code in your httpd.conf file or you could add it into you .htaccess file in the directory of choice. I think I&#8217;d prefer to add it to the directory as you&#8217;ve got greater control in future and don&#8217;t have to go mucking about with your main apache config file.</p>
<p>Please note that your apache server will have to have the <strong>headers_module</strong> up and running for this to work</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iacceptcookies.com/web-development/apache/how-can-i-have-a-file-automatically-download/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.385 seconds -->
