2014-10-07 105 views
0

用PHP我可以做拉鍊用下面的代碼PHP壓縮文件夾沒有循環

$zip = new ZipArchive; 
if ($zip->open ('test.zip', ZipArchive::CREATE)) { 
    $zip->addFile('img1.jpg', 'user.jpg'); 
    $zip->addFile('logo.jpg', 'file.jpg'); 
    $zip->addFile('avatar.jpg', 'av.jpg'); 
    //or we can even loop a directory 
    foreach(glob($dir . '/*') as $file) 
    { 
     //add each file from the directory 
    } 
    //end loop 

    $zip->close(); 
    echo 'Zipped !'; 
} else { 
    echo 'failed'; 
} 

?>

我的問題是,我們才能壓縮整個文件夾,而不構成環路,

$zip = new ZipArchive; 
    if ($zip->open ('test.zip', ZipArchive::CREATE)) { 
    $zip->addFolder('bla bla'); //like this,so that the entire files in it will be added 
     $zip->close(); 
     echo 'Zipped !'; 
    } else { 
     echo 'failed'; 
    } 
?> 

回答

1

實現將不得不循環。不幸的是ZipArchive沒有公開這樣一個功能,可以爲你做到這一點。

請參閱this thread您可以在其中獲得一個現成的功能。

+0

我認爲你是對的人! – coolguy 2014-10-07 08:52:29

相關問題