PHP | zip_entry_name() Function

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Opening a zip file
$zip_handle = zip_open("C:/xampp/htdocs/article.zip");
  
// Reading a zip entry archive 
$zip_entry = zip_read($zip_handle); 
  
// Reading the name of a zip entry archive
$file = zip_entry_name($zip_entry);
echo("File Name: " . $file);
  
// Closing the zip archive
zip_close($zip_handle);
?>

chevron_right


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

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Opening a zip file
$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);
         
        // Checking the file name of a zip archive entry 
        $file_name = zip_entry_name($zip_entry);
        echo("File Name: " . $file_name . "<br>");
    }
      
    // closing the zip archive
   zip_close($zip_handle);
else
    echo("Zip archive cannot be read.");
?>

chevron_right


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



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.