note 111705 deleted from ziparchive.addfile by aharvey
| From: | aharvey@php.net | Date: | Wed, 20 Mar 2013 18:49:05 +0000 |
| Subject: | note 111705 deleted from ziparchive.addfile by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194138@lists.php.net to get a copy of this message | ||
Note Submitter: mikael dot cordon at atos dot net
----
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â¦