PHP Requires Chilkat v11.0.0+
Chilkat2 PHP
Find a ZIP Entry by EntryID Using EntryById
See more Zip Examples
This example demonstrates how to use the EntryById method to retrieve a ZIP entry using its unique EntryID.
Each ZipEntry object has an EntryID property that uniquely identifies the entry within the currently open ZIP object.
This is useful when:
- An application stores EntryID values for later use
- ZIP entries need to be retrieved without searching by filename
- Multiple entries may have similar names or paths
The example:
- Opens a ZIP archive
-
Retrieves an entry using
EntryAt -
Saves the entry's
EntryID -
Uses
EntryByIdto retrieve the same entry later
Chilkat PHP Downloads
<?php
use Chilkat2\Zip;
use Chilkat2\ZipEntry;
// Open an existing ZIP archive.
$zip = new Zip();
try {
$zip->OpenZip('example.zip');
// Retrieve the first entry in the ZIP archive.
$entry = new ZipEntry();
$zip->EntryAt(0, $entry);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
echo "Original entry:\n";
echo ' FileName: ', $entry->FileName, "\n";
echo ' EntryID: ', $entry->EntryID, "\n";
echo "\n";
// Save the EntryID for later use.
$entryId = $entry->EntryID;
// Create another ZipEntry object.
$entry2 = new ZipEntry();
// Retrieve the same entry using EntryById.
try {
$zip->EntryById($entryId, $entry2);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
echo "Entry retrieved by EntryID:\n";
echo ' FileName: ', $entry2->FileName, "\n";
echo ' EntryID: ', $entry2->EntryID, "\n";
echo "\n";
// The filenames and EntryID values should match.
$zip->CloseZip();
echo "Done.\n";