zip_entry_compressedsize()函數是PHP中的內置函數,用於在zip存檔條目中返回壓縮文件的大小。它可用於檢索目錄條目的壓縮大小。必須讀取的zip條目資源作為參數發送到zip_entry_compressedsize()函數,並在成功時返回壓縮的大小。
用法:
int zip_entry_compressedsize ( $zip_entry )
參數:zip_entry_compressedsize()函數接受單個參數$zip_entry。它是必填參數,用於指定zip條目資源。
返回值:它在成功時返回壓縮後的大小。
錯誤與異常:
- zip_entry_compressedsize()僅在成功時返回文件或目錄的壓縮大小,否則返回PHP警告。
- 如果zip存檔無效,則zip_entry_compressedsize()函數將返回ER_OPEN錯誤。
- 如果zip存檔為空,則zip_entry_compressedsize()函數返回ER_NOZIP錯誤。
以下示例程序旨在說明PHP中的zip_entry_compressedsize()函數:
程序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);
// Chceking 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);
?>
輸出:
File Name:article/content.xlsx (6341 Bytes)
程序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.");
?>
輸出:
File Name:article/content.xlsx (6341 Bytes) File Name:article/gfg.pdf (603195 Bytes) File Name:article/image.jpeg (155736 Bytes)
相關文章:
參考: http://php.net/manual/en/function.zip-entry-compressedsize.php
相關用法
- PHP exp()用法及代碼示例
- d3.js d3.lab()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- PHP sin( )用法及代碼示例
- PHP abs()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- PHP cos( )用法及代碼示例
- PHP tan( )用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP next()用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
注:本文由純淨天空篩選整理自Shubrodeep Banerjee大神的英文原創作品 PHP | zip_entry_compressedsize() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。