Call to undefined function: zip_open()

Hi, could it be, that zenphoto 1.0.3 has problems with zlip 1.2.2 ???
I'm asking, because I'm running zenphoto on 2 different webserver (same provider)
server one (report from phpinfo):
PHP Version 4.3.11
...
ZLib Support enabled
Compiled Version 1.2.1
Linked Version 1.2.1

zenphoto works great on this one - without ANY problems!

server two:
PHP Version 4.3.11
...
ZLib Support enabled
Compiled Version 1.2.2
Linked Version 1.2.2

zenphoto works but I'm not able to upload zip-files (Fatal error: Call to undefined function: zip_open() in /home/www/web193/html/schabanack/zenphoto/zen/functions.php on line 137)

I tried the "hacked" functions.php from here - without success...

any ideas?

Comments

  • trisweb Administrator
    The new functions.php is likely not compatible with that old one... you'll have to find the specific line and replace it.

    I really should integrate that as another option, I will look into it. For now though, it requires zip file support in PHP. Ask your host if they can add it, or use FTP, which is almost easier! (BTW -- Zlib is not the same-- it is for gzip support, unfortunately not the same thing).
  • FYI:

    I just ran into this problem -- my host doesn't have the library for zip installed. When uploading a zip I'd get an error.

    The fix was to add this code to functions.php:

    function ShellFix($s)
    {
    return "'".str_replace("'", "'''", $s)."'";
    }
    function zip_open($s)
    {
    $fp = @fopen($s, 'rb');
    if(!$fp) return false;

    $lines = Array();
    $cmd = 'unzip -v '.shellfix($s);
    exec($cmd, $lines);
    $contents = Array();
    $ok=false;
    foreach($lines as $line)
    {
    if($line[0]=='-') { $ok=!$ok; continue; }
    if(!$ok) continue;
    $length = (int)$line;
    $fn = trim(substr($line,58));
    $contents[] = Array('name' => $fn, 'length' => $length);
    }
    return
    Array('fp' => $fp,
    'name' => $s,
    'contents' => $contents,
    'pointer' => -1);
    }
    function zip_read(&$fp)
    {
    if(!$fp) return false;
    $next = $fp['pointer'] + 1;
    if($next >= count($fp['contents'])) return false;
    $fp['pointer'] = $next;
    return $fp['contents'][$next];
    }
    function zip_entry_name(&$res)
    {
    if(!$res) return false;
    return $res['name'];
    }
    function zip_entry_filesize(&$res)
    {
    if(!$res) return false;
    return $res['length'];
    }
    function zip_entry_open(&$fp, &$res)
    {
    if(!$res) return false;
    $cmd = 'unzip -p '.shellfix($fp['name']).' '.shellfix($res['name']);
    $res['fp'] = popen($cmd, 'r');
    return !!$res['fp'];
    }
    function zip_entry_read(&$res, $nbytes)
    {
    $contents = '';
    while (!feof($res['fp'])) {
    $contents .= fread($res['fp'], 8192);
    }
    return $contents;
    }
    function zip_entry_close(&$res)
    {
    fclose($res['fp']);
    unset($res['fp']);
    }
    function zip_close(&$fp)
    {
    fclose($fp['fp']);
    }

    This works, but when running code with this addition in my local dev environment (which has the zip lib), I get an error that I can't redefine zip_open.

    I'm assuming that if I wrap the calls in a function_exists() check, I should be all good -- that change plus this code might be a good addition to the main codeline.
  • trisweb Administrator
    Integrating that sounds like a good idea, I'd add more checks to the output of popen though, to make sure the process returns a valid zip and no stderror, etc. Also, I'm curious as to where the `unzip` takes place... somewhere in /tmp I assume...

    Ah, and then there's the problem of Windows servers, which just won't do this. Another check. Cool, I think we can do all that...
Sign In or Register to comment.