Working with archives such as Zip, Tar, and Gz in PHP can be
cumbersome at best and nightmarish at worst. The native Zip extension
can be unpredictable and difficult to work with…but luckily, Zend to the
rescue!
The Zend Framework has an extensive library of filter components that
can modify and format your data in a dizzying array of different ways,
including working with archives. The component we are interested is Zend_Filter_Decompress.
To decompress an archive file, we simply create an instance of the Zend_Filter_Decompress class, tell it which type of archive we are working with and where to save the decompressed files, then call the object’s filter() method, passing in the path to the archive file.
//Create filter object
$filter = new Zend_Filter_Decompress(array(
'adapter' => 'Zip', //Or 'Tar', or 'Gz'
'options' => array(
'target' => '/path/to/output/directory'
)
)
);
$filter->filter('/path/to/archive/file.zip');
No comments:
Post a Comment