PHP zip_entry_name - Syntax
zip_entry_name(resource $entry): string|false
zip_entry_name() reads the name of an entry, including its path inside the ZIP archive. PHP deprecated this procedural function in 8.0. For new code, use ZipArchive::getNameIndex().
zip_entry_name()
Use ZipArchive to read entries by name in modern PHP.
To run the examples, save bbminfo.zip and bbminfo-nested-folder.zip beside your script and run it from that directory.
zip_entry_name(resource $entry): string|false
| Arguments | resource $entry |
|---|---|
| Return value | The entry name, or false on failure. |
A tutor needs an index of the handouts in an uploaded ZIP. Print each member’s full internal name so the list distinguishes folders from the files they contain.
<?php
class ZipExample {
public function processZipArchieve() {
$zipHandler = zip_open("./bbminfo-nested-folder.zip");
if(is_resource($zipHandler)) {
while($zipEntry = zip_read($zipHandler)) {
// Get the file name
$resourceName = zip_entry_name($zipEntry);
if(substr($resourceName, -1) == "/") {
echo("Directory: " . $resourceName);
} else {
echo("File: " . $resourceName);
}
echo "\n" ;
}
zip_close($zipHandler);
} else {
echo("Failed to Open. Error Code: " . $zipHandler);
}
}
}
$obj = new ZipExample();
$obj->processZipArchieve();
Directory: bbminfo-nested-folder/img/ File: bbminfo-nested-folder/img/bbminfo_icon.png File: bbminfo-nested-folder/readme.txt File: bbminfo-nested-folder/tutorial-doc.pdf
A teacher saves the bytes for the word alto in an uncompressed archive member. Read the first entry name, retaining the complete folder prefix. Which archive path appears?
The archive contains one stored member. Its entry metadata and contents can be inspected independently.
A tutor saves the bytes for glaze in a second uncompressed archive member. Read the first entry name, retaining the complete folder prefix. Which archive path appears?
The archive contains one stored member. Its entry metadata and contents can be inspected independently.
Reference: PHP manual — zip_entry_name()