A blend of programming and seo

How to create a zip archive using PHP

The following is a library that allows you to generate zip file archives using php.


<?php
include('ziplib.php');

$zipfile = new Ziplib;
$zipfile->zl_add_file('This is a test file','path/to/file','g9');
//You can stream the ZIP file or write it in a file on your server
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename=\'testfile.zip\'');
echo $zipfile->zl_pack('zip file comments');
?>

This script will dynamically create a zip archive using the files specified with zl_add_file and output it to the browser (the final zip file will be named: testfile.zip).

Options

zl_add_file allows you to specify the compression level of the file file that will be added to the archive.

  • n (none)
  • b (bzip)
  • g (gzip)

Download

The php zip library can be downloaded Here

June 17, 2009   9 Comments