Open In App

PHP | zip_entry_compressedsize() Function

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
 



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
 
// 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
 
// 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
 


Article Tags :