PHP zip_entry_name - Syntax
zip_entry_name(resource $ziphandler): string
The PHP zip_entry_name() function is used to retrieve the name of a file or directory from a specified Zip Archive Entry and it returns the compression method type only if success otherwise a PHP warning.
zip_entry_name(resource $ziphandler): string
resource $zipHandler |
Specifies the Resource Handler of a zip archive file (*Required) |
---|---|
Return string $compressionType |
Returns the name of a file or directory of the Zip archive entry only if success otherwise it will throw a PHP Warning. |
Open a zip archieve and print the name of all entries (i.e. name of all files and directories).
<?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();