Copy CodeThe code is as follows:
/* Creates a compressed zip file */
function Create_zip ($files = Array (), $destination = ", $overwrite = False) {
If the zip file already exists and overwrite is false, return false
if (file_exists ($destination) &&! $overwrite) {return false;}
VARs
$valid _files = Array ();
If files were passed in ...
if (Is_array ($files)) {
Cycle through each file
foreach ($files as $file) {
Make sure the file exists
if (file_exists ($file)) {
$valid _files[] = $file;
}
}
}
If we have good files ...
if (count ($valid _files)) {
Create the Archive
$zip = new Ziparchive ();
if ($zip->open ($destination, $overwrite? Ziparchive::overwrite:ziparchive::create)!== true) {
return false;
}
Add the Files
foreach ($valid _files as $file) {
$zip->addfile ($file, $file);
}
Debug
Echo ' The zip archive contains ', $zip->numfiles, ' files with a status of ', $zip->status;
Close the zip--done!
$zip->close ();
Check to make sure the file exists
return file_exists ($destination);
}
Else
{
return false;
}
}
/***** Example Usage ***/
$files =array (' file1.jpg ', ' file2.jpg ', ' file3.gif ');
Create_zip ($files, ' Myzipfile.zip ', true);
PHP Zip File Online decompression function code
http://www.bkjia.com/PHPjc/321861.html www.bkjia.com true http://www.bkjia.com/PHPjc/321861.html techarticle Copy the code as follows:/* Creates a compressed zip file */function Create_zip ($files = Array (), $destination = ", $overwrite = Fal SE) {//if the zip file already exists and ove ...