[gollem] Multiple downloads / ZIP |GZIP Archive?

Mike Cochrane mike at graftonhall.co.nz
Tue Jul 1 18:24:30 PDT 2003


> ----- Message from chuck at horde.org ---------
>
> There are a couple of tools in PHP - at least Archive_Tar in PEAR - for
> creating archives. It'd be great to get a patch to do this.
>
> -chuck
>
> --
> Charles Hagenbuch, <chuck at horde.org>
> The alligators were there, too, in a bathtub inside the house.

Here is some code that I use on another project to zip files:

    // compress file to zip
    require_once HORDE_BASE . '/lib/Compress.php';
    $zip = &Horde_Compress::singleton('zip');

    $files[] = array('name' => $filename,
                     'data' => $file_data);

    $output_zip_data = $zip->compress($files);

    $fp = fopen($output_zip_filename, 'wb');
    fwrite($fp, $output_zip_data);
    fclose($fp);

Also for bz and gz files:
    // compess file to bz2
    $fp = fopen($output_bz2_filename, 'wb');
    fwrite($fp, bzcompress($file_data, 9));
    fclose($fp);

    // compress file to gz
    $fp = fopen($output_gz_filename, 'wb');
    fwrite($fp, gzdeflate($file_data, 9));
    fclose($fp);

To use these, you will need to create the Tar file first and then bz or gz them.

- Mike :-)



More information about the gollem mailing list