(PHP Extension) List Files in a .zip
How to list files within a .zip
<?php
// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:
include("chilkat_9_5_0.php");
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$zip = new CkZip();
$success = $zip->OpenZip('a.zip');
if ($success != true) {
print $zip->lastErrorText() . "\n";
exit;
}
// Get the number of files and directories in the .zip
$n = $zip->get_NumEntries();
print $n . "\n";
for ($i = 0; $i <= $n - 1; $i++) {
// entry is a CkZipEntry
$entry = $zip->GetEntryByIndex($i);
if ($entry->get_IsDirectory() == false) {
// (the filename may include a path)
print $entry->fileName() . "\n";
}
}
?>
|