note 118507 added to function.zip-open
| From: | ohcc at 163 dot com | Date: | Wed, 16 Dec 2015 22:31:21 +0000 |
| Subject: | note 118507 added to function.zip-open | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204466@lists.php.net to get a copy of this message | ||
The zip archive will NOT be saved on disk before ZipArchive::close() is called. (ZipArchive::close
will be called automatically at the end of the script if you don't write that code.)
If you want to delete a file after adding it to the zip archive, you should delete it after
ZipArchive::close() is called. Otherwise, the file will be deleted before actually being added into
the archive, which will make your zip archive fail to be saved.
<?php
$za = new ZipArchive();
$za->open('./xc.zip', ZipArchive::CREATE|ZipArchive::OVERWRITE);
$file = './notes.txt';
if( true === $za->addFile($file)){
unlink($file);
}
if(!$za->close()){
echo 'failure.';
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 118.117.60.111
----
Manual Page -- http://php.net/manual/en/function.zip-open.php
Edit -- https://master.php.net/note/edit/118507
Del: integrated -- https://master.php.net/note/delete/118507/integrated
Del: useless -- https://master.php.net/note/delete/118507/useless
Del: bad code -- https://master.php.net/note/delete/118507/bad+code
Del: spam -- https://master.php.net/note/delete/118507/spam
Del: non-english -- https://master.php.net/note/delete/118507/non-english
Del: in docs -- https://master.php.net/note/delete/118507/in+docs
Del: other reasons-- https://master.php.net/note/delete/118507
Reject -- https://master.php.net/note/reject/118507
Search -- https://master.php.net/manage/user-notes.php