Open In App

PHP | zip_entry_compressedsize() Function

Last Updated : 14 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The zip_entry_compressedsize() function is an inbuilt function in PHP which is used to return the size of the compressed file in zip archive entry. It can be used to retrieve the compressed size of a directory entry. The zip entry resource which has to be read is sent as a parameter to the zip_entry_compressedsize() function and it returns the compressed size on Success.
Syntax: 
 

int zip_entry_compressedsize ( $zip_entry )

Parameters: The zip_entry_compressedsize() function accepts single parameter $zip_entry. It is a mandatory parameter which specifies the zip entry resource.
Return Value: It returns the compressed size on Success.
Errors And Exceptions
 

  • The zip_entry_compressedsize() returns the compressed size of a file or a directory only on Success otherwise it returns a PHP warning.
  • The zip_entry_compressedsize() function returns an ER_OPEN error if the zip archive is invalid.
  • The zip_entry_compressedsize() function returns an ER_NOZIP error if the zip archive is empty.

Below programs illustrate the zip_entry_compressedsize() function in PHP:
Program 1: 
 

Suppose a zip file article.zip contains the following file: 
content.xlsx 
 

 

php




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


Output: 
 

File Name: article/content.xlsx (6341 Bytes)

Program 2: 
 

Suppose a zip file article.zip contains the following file: 

content.xlsx 
gfg.pdf 
image.jpeg 

 

 

php




<?php
 
// Opening a zip archive
$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 compressed file size of
        // a zip archive entry
        $file_size = zip_entry_compressedsize($zip_entry);
         
        echo "File Name: " . $file . " (" . $file_size
              . " Bytes) " . "<br>";
     }
      
   zip_close($zip_handle);
}
else
   echo("Zip archive cannot be opened.");
?>


Output: 
 

File Name: article/content.xlsx (6341 Bytes) 
File Name: article/gfg.pdf (603195 Bytes) 
File Name: article/image.jpeg (155736 Bytes) 

Related Articles: 
 

Reference: http://php.net/manual/en/function.zip-entry-compressedsize.php
 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads