(PHP ActiveX) List Files in Zip using FirstEntry/NextEntry
Demonstrates how to iterate over the files and directories in a zip archive using the FirstEntry and NextEntry functions.
<?php
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$zip = new COM("Chilkat_9_5_0.Zip");
$success = $zip->OpenZip('qa_data/zips/xml_files.zip');
if ($success != 1) {
print $zip->LastErrorText . "\n";
exit;
}
// entry is a Chilkat_9_5_0.ZipEntry
$entry = $zip->FirstEntry();
if ($zip->LastMethodSuccess == 0) {
print 'This zip archive is empty.' . "\n";
exit;
}
$finished = 0;
while ($finished == 0) {
if ($entry->IsDirectory == 0) {
print $entry->FileName . "\n";
}
else {
print '(directory) ' . $entry->FileName . "\n";
}
// next is a Chilkat_9_5_0.ZipEntry
$next = $entry->NextEntry();
if ($entry->LastMethodSuccess == 0) {
$finished = 1;
}
// entry is a Chilkat_9_5_0.ZipEntry
$entry = $next;
}
// 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
?>
|