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

List Files in a .zip

See more Zip Examples

How to list files within a .zip

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\Zip;
use Chilkat2\ZipEntry;

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

$zip = new Zip();

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

// Get the number of files and directories in the .zip
$n = $zip->NumEntries;

$entry = new ZipEntry();

$i = 0;

while ($i < $n) {
    $zip->EntryAt($i, $entry);
    if (!$entry->IsDirectory) {
        // (the filename may include a path)
        echo $entry->FileName, "\n";
    }

    $i = $i + 1;
}