From 4b6c0e31385f5f27a151088c0a2b614495c4e589 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Thu, 14 Oct 2021 12:47:50 -0400 Subject: initial commit, including theme --- .../2007-09-22-streaming-zip-files-with-php.html | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 content/posts/2007-09-22-streaming-zip-files-with-php.html (limited to 'content/posts/2007-09-22-streaming-zip-files-with-php.html') 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 +--- + +

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

+ + + +

I wasn't particularly fond of either constraint, so I came up with a +solution: ZipStream-PHP. 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:

+ +
# 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->add_file('some_file.gif', $data);
+
+# add second file
+$data = file_get_contents('another_file.txt');
+$zip->add_file('another_file.txt', $data);
+
+# finally, finish the stream
+$zip->finish();
+
+ +

You can also set file comments and creation dates, like so:

+ +
$data = file_get_contents('foo.txt');
+$zip->add_file('foo.txt', $data, array(
+  'comment' => 'this is an interesting comment',
+  'time'    => time() - 3600, # created one hour ago
+));
+
+ +

Here are the links, enjoy:

+ + + + -- cgit v1.2.3