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. September 3rd, 2009 at 19:49 | #1

    Cool site, love the info.

  2. September 27th, 2011 at 05:26 | #2

    I’ve been absent for some time, but now I remember why I used to love this website. Thanks, I will try and check back more often. How frequently you update your web site?

  3. September 27th, 2011 at 12:40 | #3

    Great blog, I have just bookmarked it :)

  4. September 27th, 2011 at 14:41 | #4

    I would like to setup wordpress blog that would allow people to sign up to receive news letters and updates? Do I need to download wordpress to my computer? Is there any pre-made templates for this type?.

  5. September 27th, 2011 at 15:18 | #5

    I do not even know how I ended up here, but I thought this post was great. I don’t know who you are but definitely you’re going to a famous blogger if you are not already ;) Cheers!

  6. September 27th, 2011 at 18:16 | #6

    Awesome! Everything I wanted summed up in a very concise way. In my view, it’s the most excellent article I have ever read. Thanks!

  7. September 28th, 2011 at 01:10 | #7

    Great blog here! Also your web site loads up fast! What web host are you using? Can I get your affiliate link to your host? I wish my site loaded up as quickly as yours lol

  8. September 28th, 2011 at 10:52 | #8

    Thanks a lot for providing individuals with such a wonderful possiblity to read articles and blog posts from this blog. It’s usually very excellent and packed with a good time for me and my office colleagues to search your website at minimum 3 times weekly to study the latest secrets you have got. Of course, I’m just usually fulfilled with the dazzling guidelines you serve. Certain 4 tips in this post are ultimately the most effective we’ve had.

  9. October 26th, 2011 at 00:20 | #9

    I do agree with all of the ideas you’ve presented in your post. They’re really convincing and will certainly work. Still, the posts are too short for beginners. Could you please extend them a bit from next time? Thanks for the post.

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