Re: Re: On going ZipArchive saga

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On May 12, 2015, at 9:27 AM, Jeffry Killen wrote:


On May 12, 2015, at 7:13 AM, Christoph Becker wrote:

Jeffry 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]);

Added file_exists and is_readable test here
and an array for collecting files that aren't found or aren't readable

                 $_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?

At least for testing purposes, I would do

                   if($_add !== true)

                   {
                    $_addErrs[count($_addErrs)] = $_addFile;
                    continue;
                   }
                }
             $_zipper->close();

changed to  $_cls = $_zipper->close();
and added test for return value of true

                     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().

             $_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;

so, all I get is the string "ZipArchive returned false." without any listing for files that aren't found or
are not readable
>>>> I am using absolute file system file paths and not docRoot relative or absolute paths
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.


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

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().

I could have the path to the file to be added constructed wrong, but I know
the file exists. I will use that test.

[1] <http://php.net/manual/en/ziparchive.addfile.php#101605>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux