Creating a Zip in PHP is really simple, as long as the following 2 steps can be completed.
1. Please download my prepared zip.php tool class, download and unzip, put the files inside the corresponding directory, I was placed in the virtual directory in the Include folder.
2. Add the following code to your PHP file
Require_once "./include/zip.php";
$zip = new Phpzip ();
$zip-Createzip ("folder directory address to compress", "compressed file name. zip"); Generate non-automatic downloads only
$zip-Downloadzip ("folder directory address to compress", "compressed file name. zip"); Automatic download
Example: You can refer to the following pseudo-code to see a specific usage scenario:
Copy to ClipboardWhat to refer to:
[www.bkjia.com]Require_once "./include/zip.php";
if (! $download) {
Exit ();
}
Set_time_limit (60);
$tmpManager = new Tmpmanager (); Let's say we have a class to do the following
$tempfolder = Array ();
$tempfile = Array ();
Let's say we download the selected folder or file by selecting the checkbox on the page and package it together
for ($i = 0; $i < $checkboxnum; $i + +) {
$value = ${"select". $i};
if ($value! = ") {
$this _type = substr ($value, 0, 1);
$this _id = substr ($value, 1);
Handling folders and files separately
if ($this _type = = ' d ') {
$tempfolder [] = $this _id;
}
ElseIf ($this _type = = ' F ') {
$tempfile [] = $this _id;
}
}
}
@mkdir ($tempdir);
$curtempdir = "$tempdir/". $userid; Different users operate under different temporary folders
if (file_exists ($curtempdir)) {
$tmpManager->deletedir ($curtempdir); Delete the old folder
}
if (sizeof ($tempfolder) > 0 | | sizeof ($TEMPFILE) > 0) {
mkdir ($curtempdir, 0777); Re-create the folder if you have a folder to package the files
}
if (sizeof ($tempfile) > 0) {
$tmpManager->copyfile ($tempfile, $curtempdir); Copy the file you want to download to the folder you created
}
if (sizeof ($tempfolder) > 0) {
$tmpManager->copyfolder ($tempfolder, $curtempdir); Copy the folder you want to download to the folder you created
}
$zip = new Phpzip ();
$zip-Downloadzip ($curtempdir, "File_". Date (' Ymd '). ". Zip "); Package and download
Transferred from: http://www.cnblogs.com/xiaosuo/
http://www.bkjia.com/PHPjc/364396.html www.bkjia.com true http://www.bkjia.com/PHPjc/364396.html techarticle creating a Zip in PHP is really simple, as long as the following 2 steps can be completed. 1. Please download my prepared zip.php tool class, download and unzip, put the files inside the corresponding directory, I am ...