开发者

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.


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜