note 111705 added to ziparchive.addfile
| From: | mikael dot cordon at atos dot net | Date: | Tue, 19 Mar 2013 09:44:52 +0000 |
| Subject: | note 111705 added to ziparchive.addfile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194121@lists.php.net to get a copy of this message | ||
As said previously: ZipArchive::addFile() returns true even if the file does not existsâ¦
Considering the following code :
<?php
$zip = new ZipArchive () ;
$diskfile = "file:///srv/share/myfile.txt" ; // this URL points to an existing file
$zipfile = "myfile.txt" ;
if (! $zip->open ("/home/mikael/myzip.zip", ZIPARCHIVE::OVERWRITE)) {
die "Cannot open new zip" ;
}
if (! is_readable ($diskfile)) { // PHP can read file with this URL syntax
die "File is not readable" ;
}
if (! $zip->addFile ($diskfile, $zipfile)) { // Succeeds despite of $diskfile is not readable by
ZipArchive with this URL
die "Cannot add file to zip" ;
}
if (! $zip->close ()) { // Allways fails because of $diskfile is not readable for ZipArchive
die "Cannot close zip" ;
}
?>
ZipArchive does not support wrappers which are supported widely by PHPâ¦
A dirty solution:
<?php
â¦
if (! $zip->addFile (preg_replace ("#^file://#", "", $diskfile), $zipfile)) {
die "Cannot add file to zip" ;
}
â¦
?>
I scratched my head during hours before finding this issueâ¦
----
Server IP: 69.147.83.199
Probable Submitter: 145.242.11.3
----
Manual Page -- http://php.net/manual/en/ziparchive.addfile.php
Edit -- https://master.php.net/note/edit/111705
Del: integrated -- https://master.php.net/note/delete/111705/integrated
Del: useless -- https://master.php.net/note/delete/111705/useless
Del: bad code -- https://master.php.net/note/delete/111705/bad+code
Del: spam -- https://master.php.net/note/delete/111705/spam
Del: non-english -- https://master.php.net/note/delete/111705/non-english
Del: in docs -- https://master.php.net/note/delete/111705/in+docs
Del: other reasons-- https://master.php.net/note/delete/111705
Reject -- https://master.php.net/note/reject/111705
Search -- https://master.php.net/manage/user-notes.php