You need to open the archive, and then iterate over the files by index:
$zip = new ZipArchive();
if ($zip->open('archive.zip'))
{
for($i = 0; $i < $zip->numFiles; $i++)
{
echo 'Filename: ' . $zip->getNameIndex($i) . '<br />';
}
}
else
{
echo 'Error reading .zip!';
}
To read the contents of a single file, you can use ZipArchive :: getStream ($ name) .
$zip = new ZipArchive();
$zip->open("archive.zip");
$fstream = $zip->getStream("index.txt");
if(!$fp) exit("failed\n");
while (!feof($fp)) {
$contents .= fread($fp, 2);
}
Another way to do this is to use the zip: // stream wrapper:
$file = fopen('zip://' . dirname(__FILE__) . '/test.zip#test', 'r');
...
source
share