当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP zip_entry_close()用法及代码示例


zip_entry_close()函数是PHP中的内置函数,用于关闭由zip_entry_open()函数打开的zip存档。 zip_entry_close()导致流关闭,并且与相应Zip存档条目的连接可能断开,该条目可能是Zip存档中的文件或目录。必须关闭的zip条目资源作为参数发送到zip_entry_close()函数。

用法:

 bool zip_entry_close ( $zip_entry )

参数:zip_entry_close()函数接受单个参数$zip_entry。它是必填参数,用于指定zip条目资源。


返回值:成功返回true,失败返回False。

错误和异常:

  • 必须先使用PHP zip_entry_open()函数打开要关闭的zip条目档案,否则PHP zip_entry_close()函数将产生PHP警告。
  • 如果zip存档无效,则zip_entry_close()函数将返回ER_OPEN错误。
  • 如果zip存档为空,则zip_entry_close()函数返回ER_NOZIP错误。

Suppose a zip file article.zip contains the following file:
content.xlsx

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

程序1:

<?php 
  
// Opening a zip archive 
$zip_handle = zip_open("C:/xampp/htdocs/article.zip"); 
$zip_entry = zip_read($zip_handle); 
   
// Opening a zip entry archive  
zip_entry_open($zip_handle, $zip_entry, "rb"); 
$file = zip_entry_name($zip_entry); 
   
// Closing a zip entry archive  
$flag = zip_entry_close($zip_entry); 
  
if ($flag == true)  
    echo("Zip Entry Archive: " . $file . " has been closed successfully. "); 
else
    echo("Zip Entry Archive: " . $file . " cannot be closed."); 
   
zip_close($zip_handle); 
?>

输出:

Zip Entry Archive: article/content.xlsx has been closed successfully.

Suppose a zip file article.zip contains the following files:
content.xlsx
gfg.pdf
image.jpeg

程序2:

<?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))  
    {  
  
        // Opening a zip archive entry 
        $file = zip_entry_open($zip_handle, $zip_entry, "rb"); 
        $file_name = zip_entry_name($zip_entry); 
          
        if ($file == true)  
        {  
            echo("Zip Entry Archive: " . $file_name .  
                  " has been opened successfully." . "<br>"); 
  
            // Closing a zip archive entry 
            $flag = zip_entry_close($zip_entry); 
              
            if ($flag == true)  
                echo("Zip Entry Archive: " . $file_name . 
                  " has been closed successfully." . "<br>"); 
            else
                echo("Zip Entry Archive: " . $file_name . 
                              " cannot be closed." . "<br>"); 
        }  
        else
            echo("Zip Entry Cannot be opened.");  
    }  
  
    // Closing a zip archive 
    zip_close($zip_handle); 
} 
else
    echo("Failed to Open" . $zip_handle ); 
?>

输出:

Zip Entry Archive: article/content.xlsx has been opened successfully.
Zip Entry Archive: article/content.xlsx has been closed successfully.
Zip Entry Archive: article/gfg.pdf has been opened successfully.
Zip Entry Archive: article/gfg.pdf has been closed successfully.
Zip Entry Archive: article/image.jpeg has been opened successfully.
Zip Entry Archive: article/image.jpeg has been closed successfully.

参考: http://php.net/manual/en/function.zip-entry-close.php



相关用法


注:本文由纯净天空筛选整理自Shubrodeep Banerjee大神的英文原创作品 PHP | zip_entry_close() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。