請參閱this question。我不能使用該代碼:爲什麼我的郵政編碼無法按預期工作?
function addFolderToZip($dir, $zipArchive, $zipdir = ''){
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
//Add the directory
$zipArchive->addEmptyDir($dir);
// Loop through all the files
while (($file = readdir($dh)) !== false) {
//If it's a folder, run the function again!
if(!is_file($dir . $file)){
// Skip parent and root directories
if(($file !== ".") && ($file !== "..")){
addFolderToZip($dir . $file . "/", $zipArchive, $zipdir . $file . "/");
}
}else{
// Add the files
$zipArchive->addFile($dir . $file, $zipdir . $file);
}
}
}
請爲我寫一個例子。第二個問題太複雜了。
當我使用addfile
函數時,它會添加並作爲一個文件出現在存檔中,這很好。現在,當我使用:
$z = new ZipArchive();
$z->open('test.zip')
for ($i=0; $i< $z->numFiles;$i++) {
$aZipDtls = $z->statIndex($i);
echo $aZipDtls['name'];
}
它現在展示的,如果我在文件夾中添加一個文件,這樣的:
$zip->addFile('/path/to/index.txt', 'dir/newname.txt');
它顯示在WinRAR的軟一個目錄,然後一個文件,但在它的代碼顯示它作爲一個文件。
就像那個在WinRAR:
dir/
dir/newname.txt
在我的PHP系統,僅僅只顯示一個文件,沒有它的目錄,這樣的:
dir/newname.txt
這意味着它是不可能添加一個新的文件一個dir。
請解釋一下你希望我們爲你寫的例子。 – Natrium 2010-02-04 08:27:44
您的問題對我而言並不明確,而且您不使用標點或首字母,這會使您的問題難以閱讀。 – 2010-02-04 09:04:05