note 118504 added to ziparchive.addfile
| From: | ohcc at 163 dot com | Date: | Wed, 16 Dec 2015 17:04:18 +0000 |
| Subject: | note 118504 added to ziparchive.addfile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204457@lists.php.net to get a copy of this message | ||
Do NOT use ZipArchive::addFile() to append a folder.
When a folder's path is passed to ZipArchive::addFile(), the method returns true, but
ZipArchive can neither create a zip archive nor can it make any change to a existing file.
<?php
$z = new ZipArchive();
if(true === ($z->open('./foo.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE))){
$z->setArchiveComment('Interesting!');
$z->addFromString('domain.txt', 'wuxiancheng.cn');
$folder = './test';
!is_dir($folder) && mkdir($folder); // Create an folder for testing
if(true === $z->addFile($folder)){
echo 'success'; // !!!
}
rmdir($folder);
$z->close();
// foo.zip will NOT be saved on disk.
// If foo.zip already exists before we run this script, the file will remain unchanged.
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 118.117.60.111
----
Manual Page -- http://php.net/manual/en/ziparchive.addfile.php
Edit -- https://master.php.net/note/edit/118504
Del: integrated -- https://master.php.net/note/delete/118504/integrated
Del: useless -- https://master.php.net/note/delete/118504/useless
Del: bad code -- https://master.php.net/note/delete/118504/bad+code
Del: spam -- https://master.php.net/note/delete/118504/spam
Del: non-english -- https://master.php.net/note/delete/118504/non-english
Del: in docs -- https://master.php.net/note/delete/118504/in+docs
Del: other reasons-- https://master.php.net/note/delete/118504
Reject -- https://master.php.net/note/reject/118504
Search -- https://master.php.net/manage/user-notes.php