: This article mainly introduces php packaging folders into zip files. For more information about PHP tutorials, see.
Php package the folder into a zip file:
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 the content of php package the folder into a zip file. For more information, see PHP Chinese network (www.php1.cn )!