Php simple implementation of packaging folders into zip files

Source: Internet
Author: User
Tags ziparchive
The following is a simple implementation of php packaging folders into zip files. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the example below:

Function addFileToZip ($ path, $ zip) {$ handler = opendir ($ path); // specify $ path to open the current folder. While ($ filename = readdir ($ handler ))! = False) {if ($ filename! = "." & $ Filename! = ".. ") {// The folder name is '. 'and '.. ', do not operate on them if (is_dir ($ path. "/". $ filename) {// recursive addFileToZip ($ path. "/". $ filename, $ zip);} else {// add the file to the zip object $ zip-> addFile ($ path. "/". $ filename) ;}}@ closedir ($ path) ;}$ zip = new ZipArchive (); if ($ zip-> open('images.zip ', ZipArchive: OVERWRITE) === TRUE) {addFileToZip ('images/', $ zip); // call the method to operate the root directory to be packaged, and pass the ZipArchive object to the method $ zip-> close (); // close the processed zip file}

The above is a simple implementation method for php to package folders into zip files. I hope you can support PHP ~

For more information about how php can package folders into zip files, see The PHP Chinese website!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.