2010-08-04 162 views
0

使用創建ZIP文件PHP類我有下面的代碼行使用PHP創建一個zip文件

$createZip->get_files_from_folder('blog/wp-content/themes/', 'themes/'); 

難道我就在想,這個代碼從「博客/ WP文件和子目錄-content/themes /'創建一個名爲'themes'的新文件夾,然後將這些文件和子目錄放到這個主題文件夾中。

+3

我建議試試吧。你可能會得到比這裏更快的答案...... – ircmaxell 2010-08-04 12:26:33

+1

你是否意識到,你花了更多的時間輸入一個是/否的問題,而不是實際需要時間來簡單地嘗試一下? – Gordon 2010-08-04 12:27:23

+0

也許更多代碼neede(什麼是$ createZip)--- – retro 2010-08-04 12:27:35

回答

0

我不知道你正在使用,但這裏哪個班/庫是一個允許您把拉鍊出現在指定的目錄中的所有文件:

Create Zip File class

用法:

$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的正確路徑,其中的所有文件都將被壓縮。

+0

非常感謝您的幫助 – Rifki 2010-08-04 14:16:07