php zip entry open,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:

// 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:

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

// Closing a zip archive entry

$flag = zip_entry_close($zip_entry);

if ($flag == true)

echo("Zip Entry Archive: " . $file_name .

" has been closed successfully." . "
");

else

echo("Zip Entry Archive: " . $file_name .

" cannot be closed." . "
");

}

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值