Reputation: 6093
$fileToZip="License.txt";
$fileToZip1="CreateZipFileMac.inc.php";
$fileToZip2="CreateZipFile.inc.php";
$directoryToZip="../images"; // This will zip all the file(s) in this present working directory
$outputDir="/"; //Replace "/" with the name of the desired output directory.
$zipName="test.zip";
include_once("CreateZipFile.inc.php");
$createZipFile=new CreateZipFile;
//Code toZip a directory and all its files/subdirectories
$createZipFile->zipDirectory($directoryToZip,$outputDir);
$rand=md5(microtime().rand(0,999999));
$zipName=$rand."_".$zipName;
$fd=fopen($zipName, "wb");
$out=fwrite($fd,$createZipFile->getZippedfile());
fclose($fd);
$createZipFile->forceDownload($zipName);
@unlink($zipName); `
When I run this code, it creates a zip file test.zip
but when I extract it, I'll get all the files inside the images
folder and I don't want that to happen. I just want to get all the files, not in a folder, when extracting. How can I modify this code in order to achieve it? Is there any other way to do that? Thank you.
Upvotes: 3
Views: 2360
Reputation: 10848
This might be a long shot, but have you tried changing this:
$directoryToZip="../images";
to this:
$directoryToZip="../images/";
Upvotes: 0
Reputation: 20889
I think this is what you're looking for. You should be able to gut that and modify it as needed. It depends on the ZipArchive class.
Upvotes: 2