Mick Mick - 23 days ago 6
PHP Question

Zip multiple files with Zend Filter Compress

Is there a way to zip multiple files in one zip archive using Zend_Filter_Compress class ?

The official documentation only talks about one file or one folder.

Using an array as an argument for the calling method doesn't work, as the archive contains only the last file in the array.

$filter = new Zend_Filter_Compress(array(
'adapter' => 'Zip',
'options' => array(
'archive' => 'test.zip'
),
));
$b=array('C:\temp\compress1.txt','C:\temp\compress2.txt');
$compressed = $filter->filter($b);

Answer

As far as i know Zend_Filter_Compress supports only strings, single files or folders (inclusive sub-folders) for compression.

But you can create the archive by using the ZipArchive class.

See: http://www.php.net/manual/de/class.ziparchive.php

$files = array('a.txt', 'b.txt', 'c.txt');
$zip = new ZipArchive();
$zip->open('archive.zip', ZipArchive::CREATE);
foreach ($files as $file) {
    $zip->addFile($file);
}
$zip->close();