Unlike what "jana.vasseru" said 7 years ago, this method does not return FALSE for folders (anymore?). It seems that there is no way to find out if an entry is a directory of file.
(PHP 5 >= 5.2.0, PHP 7, PHP 8, PECL zip >= 1.1.0)
ZipArchive::getFromIndex — Gibt den Inhalt eines Eintrags unter Verwendung seines Index zurück
$index
, int $len
= 0
, int $flags
= 0
) : string|falseGibt den Inhalt eines Eintrags unter Verwendung seines Index zurück.
index
Index des Eintrags
len
Die von dem Eintrag zu lesende Länge.
Falls 0
, wird der gesamte Eintrag gelesen.
flags
Die Flags, die beim Öffnen des Archivs verwendet werden können. Die folgenden Werte können darauf angewendet werden (ODER verknüpft):
ZipArchive::FL_UNCHANGED
ZipArchive::FL_COMPRESSED
Gibt im Erfolgsfall den Inhalt des Eintrags zurück. Im Fehlerfall wird false
zurückgegeben.
Beispiel #1 Den Dateiinhalt auslesen
<?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
echo $zip->getFromIndex(2);
$zip->close();
} else {
echo 'Fehler';
}
?>
Unlike what "jana.vasseru" said 7 years ago, this method does not return FALSE for folders (anymore?). It seems that there is no way to find out if an entry is a directory of file.
both getFromIndex and getFromName leak memory. Beware specially if you use them inside a long running loop. Even closing and re-opening the zip file doesn't help.
For detecting folders use function ::getNameIndex:
//$zip = ZipArchive::open()
$entry = $zip->getNameIndex($i);
$isDir = (substr($entry, -1, 1) == '/');
Thanks to Alex Howansky @ http://stackoverflow.com/a/19299626/2747584