Sample code for 30+ languages & platforms
PHP Requires Chilkat v11.0.0+

List Files in Zip using EntryAt / GetNext

See more Zip Examples

Demonstrates how to iterate over the files and directories in a zip archive using EntryAt/GetNext.

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\Zip;
use Chilkat2\ZipEntry;

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

$zip = new Zip();

try {
    $zip->OpenZip('qa_data/zips/xml_files.zip');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$entry = new ZipEntry();
try {
    $zip->EntryAt(0, $entry);
    $hasMoreEntries = true;
} catch (\Chilkat2\Exception $e) {
    $hasMoreEntries = false;
}
while ($hasMoreEntries) {
    if (!$entry->IsDirectory) {
        echo $entry->FileName, "\n";
    } else {
        echo '(directory) ', $entry->FileName, "\n";
    }

    $hasMoreEntries = $entry->GetNext();
}

// Sample output showing both file and directory entries:

// a1.xml
// b1.xml
// c1.xml
// (directory) dir1/
// dir1/a2.xml
// dir1/c2.xml
// (directory) dir2/
// (directory) dir2/dir3/
// dir2/dir3/c3.xml