Zip a file or files with PHP

I provided a simple function a few days ago that would unzip a file using PHP. As is usually always the case, it was followed up by a few emails asking for the best method of zipping a file or files. As it turns out, I’ve worked through some ZIP classes over the last few days in an attempt to identify with the best means of accomplishing a similar task for an online roster suite I’m writing. In my case, I needed to zip an iCal, PDF and a few other files that I could email to a user and deliver via a forced download.

Of course, as always, there’s no better reference than the PHP manual where you’ll literally find hundreds of examples.

The PHP function

The function can easily be modified. The directory you’re writing to should have appropriate write privileges.

Zip Classes

Over at, there are literally hundreds of excellent classes written under the GPL that can be very easily implemented into your projects. Of course, there are at least a dozen classes that relate to ZIP file usage that I’d recommend.

I regularly use a ZIP class written by Er. Rochak Chauhan simply because it’s easy to use and modify. A gentleman by the name of A. Grandt has written another class based upon Chauhan’s code which offers a little more functionality. Both classes come with full documentation and out-of-the-box examples.

Shortt URL for this post:

Leave a Reply

Your email address will not be published. Required fields are marked *