tags:

views:

377

answers:

3

I have designed an online editor with which a user can create files and folders on the server. Suppose a user creates the below files and folders.

/docs/abc.txt
/docs/def.txt
/docs/work/assignment.txt

I want to write a PHP script to combine the files into a single ZIP file so that it makes it easier for the user to download them with one click.

The only purpose is that I should get a single file with the directory hierarchy maintained which the user can download and uncompress on his system to get the original files and directory structure back. I don't care even if the ZIP file is not compressed.

Note that I am using a shared server and do not have access to execute external commands.

A: 

Assuming you have permission to execute an external command, you could use exec to run an external command-line capable ZIP program such as 7-Zip.

Eric J.
Sorry, I forgot to mention that I am using a shared server and do not have the access to execute external commands.
Madhu
+2  A: 

ZipArchive class is what you need. Using this you can add directories and file to an archive.

gameover
Perfect! Thanks!!
Madhu
Always a pleasure :)
gameover
A: 

Hi,

This is a common requirement and has been solved. Try and check out this class: http://www.phpclasses.org/browse/package/2322.html

More tutorials at: http://davidwalsh.name/create-zip-php <-- this has a similar example if you scroll down http://www.w3schools.com/php/php_ref_zip.asp

Srirangan
Thanks a lot!!!
Madhu