CLXXXIV. ZIP Funktionen (Lesezugriff)

Dieses Modul benutzt die Funktionen der ZZIPlib Bibliothek von Guido Draheim um ZIP komprimierte Archive und die darin enthaltenen Dateien zu lesen.

Zu beachten ist, dass ZZIPlib nur eine Untermenge der Funktionen zur Verfügung stellt, die in einer vollständigen Implementation des ZIP Algorithmus vorhanden sind. Zur Erstellung eines ZIP Archivs muss man sich eines der üblichen ZIP Programme bedienen.

Die ZIP Unterstützung ist standardmäßig nicht aktiviert. Um die ZIP Funktionen nutzen zu können, muss PHP mit der option --with-zip kompiliert werden. Das ZIP Modul benötigt ZZIPlib version >= 0.10.6.

Anmerkung: Zip Unterstützung für PHP vor Version 4.1.0 ist als experimentell anzusehen. Dieser Abschnitt beschreibt die ZIP Unterstützung, wie sie für PHP ab Version 4.1.0 existiert.

Beispiel zur Verwendung

Dieses Beispiel öffnet ein ein ZIP Archiv, liest jede Datei innerhalb des Archivs und gibt den Inhalt zurück. Das test2.zip Archiv, das in diesem Beispiel benutzt wird, wird mit der Original Distribution der ZZIPlib Bibliothek mitgeliefert.

Beispiel 1. Beispiel zur Verwendung der Zip Funktion

<?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);

}

?>
Inhaltsverzeichnis
zip_close -- Schließt ein ZIP Archiv
zip_entry_close -- Schließt einen Verzeichniseintrag
zip_entry_compressedsize -- Ermittelt die komprimierte Größe eines Verzeichniseintrages
zip_entry_compressionmethod --  Gibt die Komprimierungsmethode eines Verzeichniseintrages zurück.
zip_entry_filesize --  Gibt die Größe eines Verzeichniseintrages zurück
zip_entry_name --  Gibt den Namen eines Verzeichniseintrages zurück
zip_entry_open --  Öffnet einen Verzeichniseintrag für den Lesezugriff
zip_entry_read -- Liest einen geöffneten Verzeichniseintrag aus
zip_open -- Öffnet ein ZIP Archiv
zip_read --  Liest den nächsten Eintrag innerhalb des ZIP Archivs
ZipArchive::addFile -- Adds a file to a ZIP archive from the given path
ZipArchive::addFromString -- Add a file to a ZIP archive using its contents
ZipArchive::close -- Close the active archive (opened or newly created)
ZipArchive::deleteIndex -- delete an entry in the archive using its index
ZipArchive::deleteName -- delete an entry in the archive using its name
ZipArchive::extractTo -- Extract the archive contents
ZipArchive::getArchiveComment -- Returns the Zip archive comment
ZipArchive::getCommentIndex -- Returns the comment of an entry using the entry index
ZipArchive::getCommentName -- Returns the comment of an entry using the entry name
ZipArchive::getFromIndex -- Returns the entry contents using its index.
ZipArchive::getFromName -- Returns the entry contents using its name.
ZipArchive::getNameIndex -- Returns the name of an entry using its index
ZipArchive::getStream -- Get a file handler to the entry defined by its name (read only).
ZipArchive::locateName -- Returns the index of the entry in the archive
ZipArchive::open -- Open a ZIP file archive
ZipArchive::renameIndex -- Renames an entry defined by its index
ZipArchive::renameName -- Renames an entry defined by its name
ZipArchive::setArchiveComment -- Set the comment of a ZIP archive
ZipArchive::setCommentIndex -- Set the comment of an entry defined by its index
ZipArchive::setCommentName -- Set the comment of an entry defined by its name
ZipArchive::statIndex -- Get the details of an entry defined by its index.
ZipArchive::statName -- Get the details of an entry defined by its name.
ZipArchive::unchangeAll -- Undo all changes done in the archive.
ZipArchive::unchangeArchive -- Revert all global changes done in the archive.
ZipArchive::unchangeIndex -- Revert all changes done to an entry at the given index.
ZipArchive::unchangeName -- Revert all changes done to an entry with the given name.