Madhu
Madhu

Reputation: 1186

Combine multiple files and folders into one file using PHP

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.

Upvotes: 0

Views: 3476

Answers (2)

gameover
gameover

Reputation: 12023

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

Upvotes: 4

Eric J.
Eric J.

Reputation: 150108

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.

Upvotes: 0

Related Questions