RSS

Create ZIP archives with PHP script and PEAR class

16 Apr

We can use PEAR to process zip files in PHP using Archive_Zip….

First set PEAR path in php include path using set_include_path

Make Zipped file

<?php
include (‘Archive/Zip.php’);        // include PEAR ZIP package

$obj = new Archive_Zip(‘test.zip’);  // zipped file name

$files = array(‘svnlabs/1.gif’,
svnlabs/resume.doc’,
svnlabs/invoice.xls’);   // files add to zip

if ($obj->create($files)) {
echo ‘Files zipped successfully!’;
} else {
echo ‘Error in file zipping’;
}
?>
List Zip file elements

<?php
include (‘Archive/Zip.php’);        // include PEAR ZIP package

$obj = new Archive_Zip(‘test.zip’); // Input zip file

$files = $obj->listContent();       // zip information

foreach ($files as $f) {
foreach ($f as $s => $v) {
echo “$s: $v\r\n”;
}
echo “\r\n”;
}
?>
I really enjoyed programming with PEAR…

Advertisements
 
1 Comment

Posted by on April 16, 2010 in CakePHP, Fedora, Linux, Open Source, PEAR, php, Tips, Tricks

 

Tags: , , , , ,

One response to “Create ZIP archives with PHP script and PEAR class

  1. blog.svnlabs.com

    October 20, 2010 at 1:36 pm

    Posted it to twitter. Greetings from the Speedy DNS.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: