zip.thumbnail

How can we zip two files and save output as output.zip. For example, in gmail you can download all the attachment as a single zip file. How can we write that code using php.

Click more for Source Code:

/* * Php code for file zip * Author : Sajith.M.R * Date: 02-02-2007 */ /* Include the Pear Library for Zip / include ('Archive/Zip.php'); /* Create a Zipping Object... * Name of zip file to be created.. * You can specify the path too / $obj = new Archive_Zip('test.zip'); /* * create a file array of Files to be Added in Zip / $files = array('black.gif', 'blue.gif', ); /* * creating zip file..if success do something else do something... * if Error in file creation ..it is either due to permission problem (Solution: give 777 to that folder) * Or Corruption of File Problem.. */ if ($obj->create($files)) { // echo 'Created successfully!'; } else { //echo 'Error in file creation'; } ?>; // We'll be outputting a ZIP header('Content-type: application/zip'); // It will be called test.zip header('Content-Disposition: attachment; filename="test.zip"'); //read a file and send readfile('test.zip'); ?>;

//This will output test.zip to the browser. If you dont want zip file as output (just saving into directory) leave the second part of above code

//This will output test.zip to the browser. If you dont want zip file as output (just saving into directory) leave the second part of above code

Note:

Download the pear library from: http://download.pear.php.net/package/Archive_Zip-0.1.1.tgz

or

install via *pear pear install http://download.pear.php.net/package/Archive_Zip-0.1.1.tgz *