Wednesday, September 25, 2024
Google search engine
HomeLanguagesPHP | zip_entry_compressedsize() Function

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
 

  • 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
 

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments