I’m using this PHP class: http://www.phpclasses.org/browse/file/9524.html
I use this code to make it work:
include('scripts/zip.php');
$directoryToZip = "./"; // This will zip all the file(s) in this present working directory
$outputDir = 'backup/'; //Replace "/" with the name of the desired output directory.
$zipName = 'backup_'.date('Y-m-d').'1.zip';
// If backup already exists, kill it
if(file_exists($outputDir.$zipName)){
unlink($outputDir.$zipName);
}
$createZipFile = new CreateZipFile;
/*
// Code to Zip a single file
$createZipFile->addDirectory($outputDir);
$fileContents=file_get_contents($fileToZip);
$createZipFile->addFile($fileContents, $outputDir.$fileToZip);
*/
//Code toZip a directory and all its files/subdirectories
$createZipFile->zipDirectory($directoryToZip,$outputDir);
$fd = fopen($outputDir.$zipName, "wb");
fwrite($fd,$createZipFile->getZippedfile());
fclose($fd);
Now as you see I tell it to .zip all directories and files using this variable:
$directoryToZip = "./";
I need to make one exception:
I don’t want the script to .zip the backup directory.
How do I add an exception?
You should override the “parseDirectory” method, as show below: