Lock all files in a directory (not in a directory) using php

$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 will get all the files inside the folder images, and I do not want this to happen. I just want to get all the files, not in the folder, when extracting. How can I change this code to achieve it? Is there any other way to do this? Thank.

+3
source share
2 answers

I think this one is what you are looking for. You should be able to get rid of it and change it as needed. It depends on the ZipArchive class .

+2
source

It may be a long shot, but you tried to change this:

$directoryToZip="../images";

:

$directoryToZip="../images/";
0
source

All Articles