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

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 )

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); 
?>

Output:

File Name: article/content.xlsx
Size: 9420 Bytes

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."); 
?>
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

Statement
This article is reproduced at:vimsky. If there is any infringement, please contact admin@php.cn delete

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.