Rumah > tajuk utama > 聊聊PHP zip_entry_filesize()函数的使用方法

聊聊PHP zip_entry_filesize()函数的使用方法

不言
Lepaskan: 2022-04-08 19:06:21
ke hadapan
3779 orang telah melayarinya

zip_entry_filesize()函数是PHP中的内置函数,用于读取zip压缩文件,下面本篇文章给大家介绍一下PHP zip_entry_filesize()函数使用方法,希望对大家有帮助。

聊聊PHP zip_entry_filesize()函数的使用方法

zip_entry_filesize()函数用于在压缩前返回zip存档条目的原始文件大小。将读取zip条目资源并将其作为参数发送给zip_entry_filesize()函数,并且在成功时它将返回以字节为单位的值。

用法:

int zip_entry_filesize( $zip_entry )
Salin selepas log masuk

参数:该函数接受强制性的单个参数$zip_entry。它是指定邮政编码条目资源的参数。

返回值:成功时返回字节值。

错误和异常:

  • zip_entry_filesize()仅在成功压缩之前返回文件的大小(以字节为单位),否则返回PHP警告。

  • 如果zip存档无效,则zip_entry_filesize()函数将返回ER_OPEN错误。

  • 如果zip存档为空,则zip_entry_filesize()函数返回ER_NOZIP错误。

以下示例程序旨在说明PHP中的zip_entry_filesize()函数:

程序1:

假设有一个zip压缩文件article.zip,zip包含以下文件:

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); 
?>
Salin selepas log masuk

输出:

File Name: article/content.xlsx
Size: 9420 Bytes
Salin selepas log masuk

程序2:

假设有一个zip压缩文件article.zip,zip包含以下文件和目录:

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."); 
?>
Salin selepas log masuk

输出:

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
Salin selepas log masuk
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan