Home headlines Let's talk about how to use the PHP zip_entry_filesize() function

Let's talk about how to use the PHP zip_entry_filesize() function

May 09, 2018 pm 03:38 PM

zip_entry_filesize() function is a built-in function in PHP, used to read zip compressed files. The following article will introduce how to use the PHP zip_entry_filesize() function. I hope it will be helpful to everyone.

Let's talk about how to use the PHP zip_entry_filesize() function

zip_entry_filesize() function is used to return the original file size of the zip archive entry before compression. The zip entry resource will be read and sent as argument to the zip_entry_filesize() function and on success it will return the value in bytes.

Usage:

int zip_entry_filesize( $zip_entry )
Copy after login

Parameters: This function accepts a mandatory single parameter $zip_entry. It is a parameter that specifies the zip code entry resource.

Return value: Returns byte value on success.

Errors and Exceptions:

  • zip_entry_filesize() returns the size of the file in bytes only before successful compression, otherwise PHP warning.

  • If the zip archive is invalid, the zip_entry_filesize() function will return an ER_OPEN error.

  • If the zip archive is empty, the zip_entry_filesize() function returns an ER_NOZIP error.

The following example program is intended to illustrate the zip_entry_filesize() function in PHP:

Program 1:

Suppose there is a zip compressed file article.zip. The zip contains the following files:

content.xlsx

<?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);  
$file = zip_entry_name($zip_entry); 
  
// Reading file size before compression 
$size = zip_entry_filesize($zip_entry); 
  
// Displaying the file ans its size 
echo("File Name: " . $file . "<br>Size:" . $size . " Bytes"); 
zip_close($zip_handle); 
?>
Copy after login

Output:

File Name: article/content.xlsx
Size: 9420 Bytes
Copy after login

Program 2:

Suppose there is a zip compressed file article.zip. The zip contains the following files and directories:

Directory: img

  • geeksforgeeks.png

  • geeksforgeeks1.png

##content.xlsx

gfg.pdf

image.jpeg

<?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 size of a zip  
        // archive entry before compression   
        $size = zip_entry_filesize($zip_entry); 
        echo("File Name: " . $file . "<br>Size: " . $size . " Bytes<br>"); 
    }  
  
    // closing the zip archive 
    zip_close($zip_handle); 
}  
else
   echo("Zip archive cannot be read."); 
?>
Copy after login
Output:

File Name: article/content.xlsx
Size: 9420 Bytes
File Name: article/gfg.pdf
Size: 621936 Bytes
File Name: article/image.jpeg
Size: 159263 Bytes
File Name: article/img/
Size: 0 Bytes
File Name: article/img/geeksforgeeks.png
Size: 751 Bytes
File Name: article/img/geeksforgeeks1.png
Size: 337 Bytes
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)