繁体   English   中英

使用php创建一个zip文件

[英]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文件夹。

我不知道您使用的是哪个类/库,但是这是一个允许您压缩指定目录中存在的所有文件的库:

创建Zip文件类

用法:

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM