[英]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 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); `
當我運行這段代碼時,它會創建一個zip文件test.zip
但是當我提取它時,我將獲取images
文件夾中的所有文件,我不希望這種情況發生。 我只想在提取時獲取所有文件,而不是文件夾中的文件。 如何修改此代碼才能實現? 還有其他辦法嗎? 謝謝。
我想這就是你要找的東西。 您應該能夠根據需要對其進行強化並進行修改。 它取決於ZipArchive類。
這可能是一個很長的鏡頭,但你嘗試改變這個:
$directoryToZip="../images";
對此:
$directoryToZip="../images/";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.