CLXXIX. Zip Fájl függvények (csak olvasáshoz)

Bevezetés

This module enables you to transparently read ZIP compressed archives and the files inside them.

Követelmények

Ez a modul a ZZIPlib könyvtár függvényeit használja. A ZZIPlib-et Guido Draheimnek köszönhetjük. A ZZIPlib 0.10.6 vagy későbbi kiadására van szükség.

Vedd figyelembe, hogy a ZZIPlib csak a teljes zip imlementációnak megfelelő tömörített zip fájlokat kezeli. A zip programkészletre is szükség van ahhoz, hogy zip fájlokat olvasson a modul.

Telepítés

Ez a PECL kiterjesztés a PHP alapterjesztésében nem szerepel. További információk, mint például új kiadások, letöltés, forrásállományok, karbantartók, CHANGELOG találhatóak itt: http://pecl.php.net/package/zip.

Installation on Linux

Installation when bundled with PHP4

In order to use these functions you must compile PHP with zip support by using the --with-zip[=DIR] configure option, where [DIR] is the prefix of the ZZIPlib library install.

Installation with PECL or bundled with PHP 5.2 or later

In order to use these functions you must compile PHP with zip support by using the --enable-zip configure option. It does not require any external library.

Megjegyzés: You can use the PECL version with PHP4. In order to do it you have to disable the bundled Zip extension or recompile PHP without it.

Installation on Windows

Installation when bundled with PHP4

Windows users will enable php_zip.dll inside of php.ini in order to use these functions. A PHP 4-es változatában ennek a kiterjesztésnek a DLL állománya (Windows esetében) az extensions/ könyvtár alatt található meg. Ezen PECL kiterjesztés DLL állományát letöltheted a PHP Letöltések, vagy a http://snaps.php.net/ címről.

Megjegyzés: 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.

Installation with PECL or bundled with PHP 5.2 or later

Windows users will enable php_zip.dll inside of php.ini in order to use these functions. A PHP 4-es változatában ennek a kiterjesztésnek a DLL állománya (Windows esetében) az extensions/ könyvtár alatt található meg. Ezen PECL kiterjesztés DLL állományát letöltheted a PHP Letöltések, vagy a http://snaps.php.net/ címről.

Futásidejű beállítások

Ez a kiterjesztés semmilyen konfigurációs beállításokat nem definiál a php.ini állományban.

Erőforrás típusok

Ez a kiterjesztés semmilyen erőforrás típust nem definiál.

Előre definiált állandók

Ez a kiterjesztés semmilyen konstans értéket nem definiál.

Példák

Az alábbi példa megnyit egy zip állományt, beolvassa a benne található fájlokat és kinyomtatja tartalmukat. A példában felhasznált test2.zip állomány a ZZIPlib csomag egyik "beépített" próba állománya.

Példa 1. Példaprogram

<?php

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

if (
$zip) {

    while (
$zip_entry = zip_read($zip)) {
        echo
"Név:                " . zip_entry_name($zip_entry) . "\n";
        echo
"Tömörítetlen méret: " . zip_entry_filesize($zip_entry) . "\n";
        echo
"Tömörített méret:   " . zip_entry_compressedsize($zip_entry) . "\n";
        echo
"Tömörítési metódus: " . zip_entry_compressionmethod($zip_entry) . "\n";

        if (
zip_entry_open($zip, $zip_entry, "r")) {
            echo
"A fájl tartalma:\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);

}

?>

A program először megnyitja a megadott útvonalon található test2.zip fájlt. A ciklust addig végzi, amíg a a zip_read() egy érvényes $zip_entry (vagyis a zip állományban létező fájl vagy könyvtár) értékkel tér vissza. A zip_read() tulajdonképpen egy tömb eléréseként képzelhető, amely tömbbe a zip_open() betölti a megnyitott zip állományban lévő fájlok neveit. Minden egyes ciklusnál a program automatikusan előre lépteti a tömböt eggyel.

Tartalom
zip_close -- Lezár egy megnyitott ZIP állományt
zip_entry_close -- Lezár egy ZIP állományban található objektumot
zip_entry_compressedsize -- Egy zip-ben lévő objektum tömörített méretét adja meg
zip_entry_compressionmethod --  A megadott zip objektum tömörítési típusát adja meg
zip_entry_filesize -- Az adott zip objektum tömörítetlen fájlméretét adja vissza
zip_entry_name -- A zip objektum nevével tér vissza
zip_entry_open -- Olvasásra megnyit egy zip objektumot
zip_entry_read -- Olvas egy megnyitott zip objektumból
zip_open -- Megnyit egy zip állományt
zip_read -- Beolvassa a következő elemet a ZIP állományból
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.