PHP | zip_entry_name() Function
Last Updated :
25 Jul, 2018
The zip_entry_name() function is an inbuilt function in PHP which is used to return the name of a zip archive entry. The zip entry resource is to be read and sent as a parameter to the zip_entry_name() function and it returns the name of the zip entry archive on Success.
Syntax:
string zip_entry_name( $zip_entry )
Parameters: This function accepts single parameter $zip_entry which is mandatory. It is used to specify the zip entry resource.
Return Value: It returns the name of a zip archive entry on Success.
Errors And Exceptions:
- The zip_entry_name() returns the name of a zip entry archive only on Success otherwise it returns a PHP warning.
- The zip_entry_name() function returns an ER_OPEN error if the zip archive is invalid.
- The zip_entry_name() function returns an ER_NOZIP error if the zip archive is empty.
Below programs illustrate the zip_entry_name() function in PHP:
Program 1:
Suppose a zip file article.zip contains the following file:
content.xlsx
<?php
$zip_handle = zip_open( "C:/xampp/htdocs/article.zip" );
$zip_entry = zip_read( $zip_handle );
$file = zip_entry_name( $zip_entry );
echo ( "File Name: " . $file );
zip_close( $zip_handle );
?>
|
Output:
File Name: article/content.xlsx
Program 2:
Suppose a zip file article.zip contains following files and directories:
Directory: img
- geeksforgeeks.png
- geeksforgeeks1.png
content.xlsx
gfg.pdf
image.jpeg
<?php
$zip_handle = zip_open( "C:/xampp/htdocs/article.zip" );
if ( is_resource ( $zip_handle ))
{
while ( $zip_entry = zip_read( $zip_handle ))
{
$file = zip_entry_name( $zip_entry );
$file_name = zip_entry_name( $zip_entry );
echo ( "File Name: " . $file_name . "<br>" );
}
zip_close( $zip_handle );
}
else
echo ( "Zip archive cannot be read." );
?>
|
Output:
File Name: article/content.xlsx
File Name: article/gfg.pdf
File Name: article/image.jpeg
File Name: article/img/
File Name: article/img/geeksforgeeks.png
File Name: article/img/geeksforgeeks1.png
Related Articles:
Reference: http://php.net/manual/en/function.zip-entry-name.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...