Mimic Gmail's "Download as .zip" feature

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm in the process of making a custom directory listing script for my
website, and I want to learn how to mimic Gmail's feature that lets
you download all the attachments in an e-mail as a single .zip file.

I have lots of little folders which some of my users need to
frequently download the contents of, so I'm curious how this is done.

Does anyone have any suggestions to at least get me started in the
right direction?

Re: Mimic Gmail's "Download as .zip" feature

techusky@gmail.com wrote:
Quoted text here. Click to load it

You could use the Zip file functions if your PHP installation was
compiled with zip support: http://www.php.net/manual/en/ref.zip.php
or use the exec() command to zip the files using the zip binary on
your system and present the zip file for download.

On-the-fly, you could send them to a script that does this.

Your link:

<a href="zipem.php">Download zipped</a>

Your code (zipem.php):


    header("Content-type: application/zip");
    print file_get_contents($zip_filename);

Or, instead of reading the entire (possibly large) file into memory,
you could redirect them to the URL of where the newly created zip
file is, assuming that it is located within the DocumentRoot of
the server.


    header("Location: /path/to/zip/file.zip");

Hope this helps..

Matt M.

Site Timeline