I found this great class, all works well except… I spcify the output directory like so:
$outputDir = "/backup/";
But it doesn’t output the zip there, it outputs it on the site root.
This is the link to the class sothat you can check it out 🙂
http://www.phpclasses.org/browse/file/9525.html
I appreciate any help!
This is the whole code where I call the class:
include('scripts/zip.php');
$fileToZip = "License.txt";
$fileToZip1 = "CreateZipFileMac.inc.php";
$fileToZip2 = "CreateZipFile.inc.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 = "test.zip";
$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($zipName, "wb");
fwrite($fd,$createZipFile->getZippedfile());
fclose($fd);
There is no code which can save output file to a directory.
With $outputDir you only define a part of output filename.
If you want to save this file, you have to do it by yourself.
Try to add something like this in demo: