文件正在压缩..但是一旦我解压缩zip文件,结果就是单个文件..不是多个文件。如何使用zend过滤器(Zip)压缩多个文件..?
这是我的代码..
//zip part
$filter = new Compress(array(
'adapter' => 'Zip',
'options' => array(
'archive' => TEMP_UPLOAD_PATH . DIRECTORY_SEPARATOR. "download" . DIRECTORY_SEPARATOR . $result['downloadResult']->r_download_id.'.zip'
)
));
$file_list = scandir(TEMP_UPLOAD_PATH . DIRECTORY_SEPARATOR. "download". DIRECTORY_SEPARATOR . $result['downloadResult']->r_download_id);
if(count($file_list) >2){
foreach ($file_list as $file) {
if (in_array($file, array(".",".."))) continue;
$filter->filter(TEMP_UPLOAD_PATH . DIRECTORY_SEPARATOR. "download". DIRECTORY_SEPARATOR . $result['downloadResult']->r_download_id . DIRECTORY_SEPARATOR . $file);
}
}
//zip end
答案 0 :(得分:1)
每次$filter->filter(…)
次调用都会创建一个只包含一个文件的新存档,并覆盖包含上一个文件的现有存档。解决方案:
$filter = new Compress([
'adapter' => 'Zip',
'options' => [
'archive' => TEMP_UPLOAD_PATH . DIRECTORY_SEPARATOR . 'download'
. DIRECTORY_SEPARATOR . $result['downloadResult']->r_download_id . '.zip'
]
]);
// assuming you _can_ create archive from the whole directory
$filter->filter(TEMP_UPLOAD_PATH . DIRECTORY_SEPARATOR . 'download'
. DIRECTORY_SEPARATOR . $result['downloadResult']->r_download_id);