aboutsummaryrefslogtreecommitdiff
path: root/content/posts/2007-09-22-streaming-zip-files-with-php.html
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2021-10-14 12:47:50 -0400
committerPaul Duncan <pabs@pablotron.org>2021-10-14 12:47:50 -0400
commit4b6c0e31385f5f27a151088c0a2b614495c4e589 (patch)
tree12243cdcd00704bc1a9d94ac9cc128459417370c /content/posts/2007-09-22-streaming-zip-files-with-php.html
downloadpablotron.org-4b6c0e31385f5f27a151088c0a2b614495c4e589.tar.bz2
pablotron.org-4b6c0e31385f5f27a151088c0a2b614495c4e589.zip
initial commit, including theme
Diffstat (limited to 'content/posts/2007-09-22-streaming-zip-files-with-php.html')
-rw-r--r--content/posts/2007-09-22-streaming-zip-files-with-php.html55
1 files changed, 55 insertions, 0 deletions
diff --git a/content/posts/2007-09-22-streaming-zip-files-with-php.html b/content/posts/2007-09-22-streaming-zip-files-with-php.html
new file mode 100644
index 0000000..3a70295
--- /dev/null
+++ b/content/posts/2007-09-22-streaming-zip-files-with-php.html
@@ -0,0 +1,55 @@
+---
+date: "2007-09-22T05:40:41Z"
+title: Streaming Zip Files with PHP
+---
+
+<p>The problem: how do you dynamically generate arbitrarily large
+downloadable zip files from PHP? All of the existing solutions I found
+all generate a local temp file, which means the server needs to </p>
+
+<ul>
+<li>have a web-writable directory large enough to store the
+intermediate temp file, and</li>
+<li>be able to generate and start streaming the entire file before
+the client times out </li>
+</ul>
+
+<p>I wasn't particularly fond of either constraint, so I came up with a
+solution: <a href="http://pablotron.org/software/zipstream-php/" title="ZipStream-PHP project page.">ZipStream-PHP</a>. ZipStream is a library for dynamically
+streaming dynamic zip files from PHP without writing to the disk at all
+on the server. Using it is dirt simple, too. Here's how:</p>
+
+<pre><code># create a new stream object
+$zip = new ZipStream('example.zip');
+
+# then add one or more files
+
+# add first file
+$data = file_get_contents('some_file.gif');
+$zip-&gt;add_file('some_file.gif', $data);
+
+# add second file
+$data = file_get_contents('another_file.txt');
+$zip-&gt;add_file('another_file.txt', $data);
+
+# finally, finish the stream
+$zip-&gt;finish();
+</code></pre>
+
+<p>You can also set file comments and creation dates, like so:</p>
+
+<pre><code>$data = file_get_contents('foo.txt');
+$zip-&gt;add_file('foo.txt', $data, array(
+ 'comment' =&gt; 'this is an interesting comment',
+ 'time' =&gt; time() - 3600, # created one hour ago
+));
+</code></pre>
+
+<p>Here are the links, enjoy:</p>
+
+<ul>
+<li><a href="http://pablotron.org/files/zipstream-php-0.1.1.tar.gz" title="ZipStream-PHP 0.1.1 tarball.">Download ZipStream-PHP 0.1.1</a> (<a href="http://pablotron.org/files/zipstream-php-0.1.1.tar.gz.asc" title="PGP signature for ZipStream-PHP 0.1.1 tarball.">Signature</a>)</li>
+<li><a href="http://hg.pablotron.org/zipstream-php/" title="ZipStream-PHP Mercurial repository.">ZipStream Mercurial Repository</a></li>
+</ul>
+
+