Re: On going ZipArchive saga

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

 



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]);
>                    $_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();

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

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

-- 
Christoph M. Becker

-- 
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