Reputation: 3975
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);
Upvotes: 0
Views: 155
Reputation: 109
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:
$fs = fopen($outputDir."/".$zipName, "wb");
fwrite($fs, $createZipFile->getZippedfile());
fclose($fs);
Upvotes: 1
Reputation: 504
My guess is that $outDir
refers to a filesystem path, so you are looking at for the folder /backup
in the root of your filesystem (and not relative to the root folder for your domain).
It is likely PHP cannot write here so possibly defaults to where it can.
Have you tried /var/www/path/to/you/site/backup
to see if that has the desired effect?
Upvotes: 1