<?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>PHP Software Developing &#187; Download</title>
	<atom:link href="http://www.phpdeveloping.co.za/category/download/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpdeveloping.co.za</link>
	<description>for the love of PHP Development</description>
	<lastBuildDate>Tue, 29 Sep 2009 15:38:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Downloading PDF files</title>
		<link>http://www.phpdeveloping.co.za/download/downloading-pdf-files.html</link>
		<comments>http://www.phpdeveloping.co.za/download/downloading-pdf-files.html#comments</comments>
		<pubDate>Thu, 10 Sep 2009 05:45:47 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Download]]></category>
		<category><![CDATA[cURL]]></category>
		<category><![CDATA[pdf]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=135</guid>
		<description><![CDATA[If you&#8217;ve done the Thirty Day Challenge, you&#8217;ll know how tedious it can be to download all the PDF files.  Norio created a cool downloading script that saved me a lot of time.  I was just too lazy to sit and write something like it, so I&#8217;m stealing his!

&#60;?php
// make sure our download [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve done the <a href="http://www.thirtydaychallenge.com">Thirty Day Challenge</a>, you&#8217;ll know how tedious it can be to download all the PDF files.  <a href="http://www.norio.co.za">Norio</a> created a cool downloading script that saved me a lot of time.  I was just too lazy to sit and write something like it, so I&#8217;m stealing his!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// make sure our download doesn't time out or get interrupted by closing the browser</span>
<span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ignore_user_abort</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// destination to download to</span>
<span style="color: #000088;">$file_dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;sites/default/files/30dc&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// create the destination directory if it doesn't exist</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// go through each day of training (1-31)</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">31</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// download the HTML contents of the training page for that day</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.thirtydaychallenge.com/training/2009day&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%02d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// provide some feedback on where we are</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;b&gt;Day <span style="color: #006699; font-weight: bold;">$i</span>:&lt;/b&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// flush output to browser - see php.net/flush</span>
    <span style="color: #990000;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// directory to download the current day's PDFs to</span>
    <span style="color: #000088;">$daydir</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$file_dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/day<span style="color: #006699; font-weight: bold;">$i</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// create the directory if it doesn't exist</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$daydir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$daydir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// grab all the URLs to the PDFs (regular expressions are awesome!)</span>
    <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'~(http://media.thirtydaychallenge.com.s3.amazonaws.com/training09/([0-9A-Za-z_]+.pdf))~'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// go through each url we grabbed above</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// check if the file already exists (no use in re-downloading PDFs we have)</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// provide some feedback on where we are</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Downloading {<span style="color: #006699; font-weight: bold;">$matches[2]</span>[<span style="color: #006699; font-weight: bold;">$key</span>]}.&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// flush output to browser</span>
        <span style="color: #990000;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// download the pdf and store it locally</span>
        <span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$daydir}</span>/{<span style="color: #006699; font-weight: bold;">$matches[2]</span>[<span style="color: #006699; font-weight: bold;">$key</span>]}&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><a target=_blank href="http://php.boff.co.za/quick-pdf-downloading-script-done-php">Check out the full post at Boff.co.za</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/download/downloading-pdf-files.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File download through your script</title>
		<link>http://www.phpdeveloping.co.za/download/file-download-through-your-script.html</link>
		<comments>http://www.phpdeveloping.co.za/download/file-download-through-your-script.html#comments</comments>
		<pubDate>Thu, 23 Jul 2009 14:21:24 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Download]]></category>
		<category><![CDATA[download control]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=48</guid>
		<description><![CDATA[There are many uses in being able to have someone download a file using your script.  Security and user verification just being one of them.
Quick way to do this:

$file = file_get_contents&#40;'file.zip'&#41;;
header&#40;'Content-Type: application/zip'&#41;;
header&#40;'Content-Disposition: attachment; filename=&#34;file.zip&#34;'&#41;;
header&#40;'Content-Length: ' . strlen&#40;$file&#41;&#41;;
echo $file;

This will send the file to the person&#8217;s browser and download the file.  You can now [...]]]></description>
			<content:encoded><![CDATA[<p>There are many uses in being able to have someone download a file using your script.  Security and user verification just being one of them.</p>
<p>Quick way to do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'file.zip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: application/zip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: attachment; filename=&quot;file.zip&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span></pre></div></div>

<p>This will send the file to the person&#8217;s browser and download the file.  You can now go ahead and add various checks before you actually start sending the data to them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/download/file-download-through-your-script.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
