PHP - Manual: ZipArchive::registerCancelCallback
2024-11-13
(PHP >= 8.0.0, PECL zip >= 1.17.0)
ZipArchive::registerCancelCallback — Register a callback to allow cancellation during archive close.
Register a callback
function to allow cancellation during archive close.
callback
If this function return 0 operation will continue, other value it will be cancelled.
成功时返回 true
, 或者在失败时返回 false
。
This example creates a ZIP file archive php.zip and cancel operation on some run condition.
示例 #1 Archive a file
<?php
$zip = new ZipArchive();
if ($zip->open('php.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
$zip->addFile(PHP_BINARY, 'php');
$zip->registerCancelCallback(function () {
return ($someruncondition ? -1 : 0);
});
$zip->close();
}
注意:
This function is only available if built against libzip ≥ 1.6.0.
官方地址:https://www.php.net/manual/en/ziparchive.registercancelcallback.php