On going ZipArchive saga

From: Date: Tue, 12 May 2015 06:13:24 +0000
Subject: On going ZipArchive saga
Groups: php.general 
Request: Send a blank email to php-general+get-324884@lists.php.net to get a copy of this message
Hello, again; I hate to be a pain in the A**, and I hate to have a continuing pain in the A** Here is another obstruction: The zip file is being created as far as ZipArchive->open is concerned: but it isn't (I already discovered that open with ZipArchive::CREATE will return true when nothing is written to the zip file: an empty file, AND the file will not have been created) So, here goes: This is not the result of an async and is not the result of wrapping zipArchive object instance in a class def on my own. It is the result of a formal post submission. I have created a custom method of encoding post vars for this application: When decoded the pattern is: n-value:l-value|s-value:t-value[|s-value:t-value[|..etc..] Where the first pair are n- for zip file name to be created and l- for directory location The rest are files to add (s-) and what to call them (t-) in the zip file. In the first line $_outPut is the result of decoding my custom encoding scheme
         $_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?
                     {
                      $_addErrs[count($_addErrs)] = $_addFile;
                      continue;
                     }
                  }
               $_zipper->close();
               $_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; from php manual: Description bool ZipArchive::addFile ( string $filename [, string $localname = NULL [, int $start = 0 [, int $length = 0 ]]] ) Adds a file to a ZIP archive from a given path. ....etc.... Return Values Returns TRUE on success or FALSE on failure. 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 I have been nit picking and chasing bubbles out of this wall paper to death, but maybe I have missed something significant. Thanks to anyone with the patience for the time and attention JK

« previous php.general (#324884) next »