开发者

Zip all the files in a directory(not the 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 Cr开发者_StackOverfloweateZipFile;


//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.


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.


This might be a long shot, but have you tried changing this:

$directoryToZip="../images";

to this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜