PHP 8.4.24 Released!

Voting

: three minus zero?
(Example: nine)

The Note You're Voting On

ohcc at 163 dot com
10 years ago
With PHP 5.6+, you may come up with theses errors.

Warning: Unknown: Cannot destroy the zip context in Unknown on line 0

Warning: ZipArchive::close(): Can't remove file: No such file or directory in xxxx.php on line xx

Examples

Warning: Unknown: Cannot destroy the zip context in Unknown on line 0

<?php         
    $za = new ZipArchive;
    $za->open('51-n.com.zip',ZipArchive::CREATE|ZipArchive::OVERWRITE);
?>

Warning: ZipArchive::close(): Can't remove file: No such file or directory in xxxx.php on line xx

<?php         
    $za = new ZipArchive;
    $za->open('51-n.com.zip',ZipArchive::CREATE|ZipArchive::OVERWRITE);
    $za->close();
?>

It happens when the zip archive is empty.
Your zip archive will not be saved on disk unless it has at least one file. What's more, when ZipArchive::OVERWRITE is applied, if there exists a file with the same name, it will be removed after ZipArchive::open() is called.

So, don't forget to put at least one file to your zip archive.

<?php         
    $za = new ZipArchive;
    $za->open('51-n.com.zip',ZipArchive::CREATE|ZipArchive::OVERWRITE);
    $za->addFromString('wuxiancheng.cn.txt','yes');
    $za->close();
?>

<< Back to user notes page

To Top