views:

377

answers:

5

This is another question based on an answer that was given to me.

What I need is the ability to do a system command line zip of large files based on what the web user selects and then prompt them or force a download. Can this be done?

A: 

How about gzip?

Assaf Lavie
Most (Windows) users won't have something like 7-zip to open these though :)
Ross
+3  A: 

This can definitely be done - in fact there are many different ways to do it. One way would be to use the PHP Zip extension (http://www.php.net/manual/en/book.zip.php) to make the file archive. Then, to let the user download the file, you'll need to set the headers of your download page, like so:

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
Steven Oxley
+1  A: 

You may want to refer to phpMyAdmin's implementation as an example of a PHP-only implementation. Download it at phpmyadmin.net and see libraries/zip.lib.php.

PCheese
A: 

why not use the zip/unzip linux utilities? run 'zip --help' in a linux commandline for details

Quamis
A: 

I would recommend using wonderful (and simple) PCLZip library: http://www.phpconcept.net/pclzip/index.en.php

You can then send the file with the headers as proposed above.

dusoft