[英]Using php to create a zip file
使用Create ZIP File PHP類,我有以下代碼行
$createZip->get_files_from_folder('blog/wp-content/themes/', 'themes/');
我是否認為該代碼從'blog / wp-content / themes /'獲取文件和子目錄是正確的,所以創建了一個名為'themes'的新文件夾,然后將這些文件和子目錄放入此theme文件夾。
我不知道您使用的是哪個類/庫,但是這是一個允許您壓縮指定目錄中存在的所有文件的庫:
用法:
$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="/"; //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);
只需指定變量$directoryToZip
的正確路徑,該文件中的所有文件都會被壓縮。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.