Re: Re: On going ZipArchive saga
| From: | Jeffry Killen | Date: | Tue, 12 May 2015 17:23:15 +0000 |
| Subject: | Re: Re: On going ZipArchive saga | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324888@lists.php.net to get a copy of this message | ||
On May 12, 2015, at 9:27 AM, Jeffry Killen wrote:
On May 12, 2015, at 7:13 AM, Christoph Becker wrote:Added file_exists and is_readable test here and an array for collecting files that aren't found or aren't readableJeffry Killen wrote:$_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]);
changed to $_cls = $_zipper->close(); and added test for return value of trueAt least for testing purposes, I would do$_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){ $_addErrs[count($_addErrs)] = $_addFile; continue; } } $_zipper->close();
if($_cls == true)
{
$_res = "Zip archive file: ".$_name."
created\n".implode($_outList, "\n");
}
else
{
$_res = "ZipArchive returned false."
$_res .= "\n".implode(<files not found or not readable array>, "\n")
}
It's better to check the return value of ZipArchive::close().
so, all I get is the string "ZipArchive returned false." without any listing for files that aren't found or are not 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;
Like localhost/path-to-file/file Ah... is there another compression scheme I can use in php to create archive files... Gzip or bzip? I have looked and don't see any explicit create function for these.I am using absolute file system file paths and not docRoot relative or absolute paths
I could have the path to the file to be added constructed wrong, but I know the file exists. I will use that test.The whole point is that ZipArchive->addFile is returning true and the files are NOT being added, so the zip file in not actually createdThere 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().[1] <http://php.net/manual/en/ziparchive.addfile.php#101605>