CVII. Zip File Functions (Read Only Access)

This module uses the functions of the ZZIPlib library by Guido Draheim to transparently read ZIP compressed archives and the files inside them.

Please note that ZZIPlib only provides a subset of functions provided in a full implementation of the ZIP compression algorithm and can only read ZIP file archives. A normal ZIP utility is needed to create the ZIP file archives read by this library.

Zip support in PHP is not enabled by default. You will need to use the --with-zip configuration option when compiling PHP to enable zip support. This module requires ZZIPlib version >= 0.10.6.

Note: Zip support before PHP 4.1.0 is experimental. This section reflects the Zip extension as it exists in PHP 4.1.0 and later.

Example Usage

This example opens a ZIP file archive, reads each file in the archive and prints out its contents. The test2.zip archive used in this example is one of the test archives in the ZZIPlib source distribution.

Example 1. Zip Usage Example

<?php

$zip = zip_open("/tmp/test2.zip");

if ($zip) {

    while ($zip_entry = zip_read($zip)) {
        echo "Name:               " . zip_entry_name($zip_entry) . "\n";
        echo "Actual Filesize:    " . zip_entry_filesize($zip_entry) . "\n";
        echo "Compressed Size:    " . zip_entry_compressedsize($zip_entry) . "\n";
        echo "Compression Method: " . zip_entry_compressionmethod($zip_entry) . "\n";

        if (zip_entry_open($zip, $zip_entry, "r")) {
            echo "File Contents:\n";
            $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
            echo "$buf\n";

            zip_entry_close($zip_entry);
        }
        echo "\n";

    }

    zip_close($zip);

}

?>
Table of Contents
zip_close -- Close a Zip File Archive
zip_entry_close -- Close a Directory Entry
zip_entry_compressedsize -- Retrieve the Compressed Size of a Directory Entry
zip_entry_compressionmethod --  Retrieve the Compression Method of a Directory Entry
zip_entry_filesize --  Retrieve the Actual File Size of a Directory Entry
zip_entry_name -- Retrieve the Name of a Directory Entry
zip_entry_open -- Open a Directory Entry for Reading
zip_entry_read -- Read From an Open Directory Entry
zip_open -- Open a Zip File Archive
zip_read -- Read Next Entry in a Zip File Archive