Re: On going ZipArchive saga
| From: | Jeffry Killen | Date: | Tue, 12 May 2015 16:27:13 +0000 |
| Subject: | Re: On going ZipArchive saga | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324887@lists.php.net to get a copy of this message | ||
On May 12, 2015, at 7:13 AM, Christoph Becker wrote:
Jeffry Killen wrote:I could have the path to the file to be added constructed wrong, but I know the file exists. I will use that test.At least for testing purposes, I would do$_elements = explode('|', $_outPut); $_addErrs = array(); $_zipper = new ZipArchive; $_head = explode(':', $_elements[0]); $_name = str_replace('l-', '', $_head[1]).'/'.str_replace('n-','', $_head[0]);$_dir = dirname($_docRoot.'/'.$_name); if(is_writable($_dir)) { $_ret = $_zipper->open($_name, ZipArchive::CREATE); if($_ret === true) { /* so now for the items sent to add */ $_outList = array(); for($_itr = 1; $_itr < count($_elements); $_itr++) { $_sep = explode(':', $_elements[$_itr]); $_addFile = $_docRoot.'/'.str_replace('s-', '',$_sep[0]);$_outList[count($_outList)] = $_addFile." ->".str_replace('t-', '', $_sep[1]);$_add = $_zipper->addFile($_addFile,str_replace('t-', '', $_sep[1]));if($_add === false) // perhaps I shouldn't use === here?if($_add !== true)It's better to check the return value of ZipArchive::close().{ $_addErrs[count($_addErrs)] = $_addFile; continue; } } $_zipper->close();There is a user contributed note[1] on the man page stating that adding non-existing files would succeed and return TRUE; I have not been able to reproduce that, but it might be worthwhile to add a check for is_readable().$_res = "Zip archive file: ".$_name."created\n".implode($_outList, "\n");if(count($_addErrs) > 0) { $_res .= "\nadd errors: ".implode($_addErrs, "\n"); } } else { require_once("php/zpArchConst.php"); $_res = $_constER[$_ret]; } }The output back to the submitting page: Zip archive file: /dev_lab_current/lab_8/storage/new.zip created /Library/WebServer/Documents/dev_lab_current/consoleTestGrid.txt -> testGrid.txt NOTICE: the lack of $_addErrs in the output; The whole point is that ZipArchive->addFile is returning true and the files are NOT being added, so the zip file in not actually created
[1] <http://php.net/manual/en/ziparchive.addfile.php#101605>Thank you for time and attention. JK