If the directory you are writing or saving into does not have the correct permissions set, you won't get any error messages and it will look like everything worked fine... except it won't have changed!
Instead make sure you collect the return value of ZipArchive::close(). If it is false... it didn't work.
ZipArchive::open
(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)
ZipArchive::open — Öffnet ein ZIP-Dateiarchiv
Beschreibung
Öffnet ein neues ZIP-Archiv für Lese-, Schreib- und Veränderungszugriffe.
Parameter-Liste
-
filename -
Der Name des zu öffnenden ZIP-Archivs.
-
flags -
Der Modus, in dem das zu öffnende Archiv verwendet werden soll.
-
ZIPARCHIVE::OVERWRITE -
ZIPARCHIVE::CREATE -
ZIPARCHIVE::EXCL -
ZIPARCHIVE::CHECKCONS
-
Rückgabewerte
-
Fehlercodes -
Gibt
TRUEoder den Fehlercode zurück.-
ZIPARCHIVE::ER_EXISTS -
ZIPARCHIVE::ER_INCONS -
ZIPARCHIVE::ER_INVAL -
ZIPARCHIVE::ER_MEMORY -
ZIPARCHIVE::ER_NOENT -
ZIPARCHIVE::ER_NOZIP -
ZIPARCHIVE::ER_OPEN -
ZIPARCHIVE::ER_READ -
ZIPARCHIVE::ER_SEEK
-
Beispiele
Beispiel #1 Öffnen und extrahieren
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip');
if ($res === TRUE) {
echo 'ok';
$zip->extractTo('test');
$zip->close();
} else {
echo 'Fehler, Code:' . $res;
}
?>
Beispiel #2 Ein Archiv erstellen
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFromString('test.txt', 'Der Dateiinhalt kommt hier');
$zip->addFile('data.txt', 'eintragsname.txt');
$zip->close();
echo 'ok';
} else {
echo 'Fehler';
}
?>
ZipArchive::open
02-Jul-2007 02:07