On creation of zip-files using PHP

January 2nd, 2009

Problem: The subject describes the problem and situation quite comprehensively. Just putting down my observations here.

Solution options: Well, I tried out many libraries and finally used none. In any case, here is my experience.

1.) Ziplib library from phpclasses - Very powerful library, can be used for recursively adding folders to an archive, etc. Just seemed to be too complicated for my task.

2.) Lib by devco.net - Simple usage and fairly good lib. This is how I tried using it: -

require (”pclzip.lib.php”);
$exp = “63″;
$zipfile = new PclZip(”$exp”.”_pack.zip”);
error_reporting(E_ALL);
$output = shell_exec( “cp index.php 63″ );
$v_list = $zipfile->create(”$exp”);

The issue I had with this one was that it didn’t allow me to add subdirectory structures selectively, or at least I couldn’t fig it out rightaway.

3.) Yet another library, this one was by Drupal - Seemed similar to 1.) and again, I just realized mid-way that I needn’t have that much functionality at all and wanted something simpler.

4.) Another one by granthinkson - Neat library, esp if you want to get all dirty with the actual file-creation and understanding process. I just wanted my zip :sigh:.

5.) Yet another by Techrepublic - Again, simple usage and I would’ve almost gone with this, but for point (6.) below. But, in any case, fairly easy to use this -

$obj = new Archive_Zip(’63.zip’);
$files = array(’63.soft’,'63.chp’, ‘63.cel’);
$obj->create($files);

6.) Well, dunno why, but I had my usual whim and I suddenly decided not to go with any of these and resorted back to plain old ‘jar’ util. So, this is what I did finally, esp since our server is configured with a jre anyways.

/* Modified: 1-1-09 | code for zip creation - pandit */
…..
$zipfilename = “$exp”.”_pack.zip”;
……
if(!file_exists(”$tmp_dir/$zipfilename”)) {
$src = “$root_dir/ftp/pub/$exp/*”;
$dest = “$tmp_dir/$exp”;
exec( “cp $src $dest” );
exec (”jar cfM $tmp_dir/$zipfilename -C $dest .”);
}
……
$zip_link = $base_url . “/$zipfilename”;

But, thats so trivial, said Watson.. Yup, everything becomes trivial after explanation, sighed Holmes.

Anyhow, I implemented it here

Share/Save/Bookmark

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon

sushain Comparison , , , ,

  1. No comments yet.
  1. January 7th, 2009 at 04:56 | #1