ZIP files not uploading

When I try to upload a ZIP file through the admin interface, I get this error:

Fatal error: Call to undefined function: zip_open() in /home/myusername/public_html/chusy/pictures/zen/functions.php on line 102

What's wrong?

Comments

  • trisweb Administrator
    You need ZIP support in PHP in order to use zip files. Contact your host and see if they can add it, and if not, might I reccomend using FTP instead? I find it much easier anyway.
  • I had the same problem: at my host the zip_open function also doesn't work, and I got the same error message.

    However, with a little tweak to the functions.php file, I've managed to fix this by calling on the unzip utility instead.

    My fix: download link

    Simply backup your existing functions.php file (it's in the /zen folder) and put this one in its place.

    I've only tested this on my host (I'm with Dreamhost), so I cannot promise anything to anyone, but at least since no functions are changed only added, it shouldn't break anything.

    More information on substituting zip_open by unzip at http://php.net/zip_open
  • trisweb Administrator
    Good info, thanks!
  • I've updated your tweaked functions.php file for zenphoto 1.0.6.
    Also made some changes to support folders in the zip files and to exclude some hidden files (__MACOSX, .file and so on)

    download link: functions.php
  • Hey- does that mean that hack was actually of some use to anyone? That's great to hear!

    Thanks for the update; my own installation hasn't made it to 1.0.6 yet, but I'll try your hack as soon as I get around to upgrading.
  • When I installed ZenPhoto for the first time (1 or 1,5 years ago), it turned out that my web host doesn’t have ZIP support. It hasn’t actually made me sad, and a build-in UnZip function was easily replaced with an amazing PclZip library (http://www.phpconcept.net/pclzip/index.en.php), so we don't need any ZIP support in PHP anymore.

    Good luck!

    P.S.

    If someone remembers I was already offering to use PclZip:

    http://www.zenphoto.org/support/topic.php?id=338&replies=5#post-1697
  • Just rewrote the function.php from version 1.03 using the PclZip library..
    You have to download the PclZip lib from the download adress above and place pclzip.lib.php into you zen-folder.. then you have to replace the unzip-function in functions.php with the following code:
    `// Unzip function; ignores ZIP directory structure.

    // Requires PclZip Lib

    require_once(dirname(__FILE__) . "/pclzip.lib.php");

    function myPreExtractCallBack($p_event, &$p_header)

    {

    $info = pathinfo($p_header['filename']);

    if (in_array(strtolower($info['extension']), array('jpg','jpeg','gif','png'))) {

    return 1;

    } else {

    return 0;

    }

    }

    function unzip($file, $dir) {

    $zip = new PclZip($file);

    if (($list = $zip->listContent()) == 0) {

    die("Error : ".$zip->errorInfo(true));

    }

    for ($i=0; $i
    if ($zip->extract( PCLZIP_OPT_PATH, $dir,

    PCLZIP_OPT_SET_CHMOD, 0777,

    PCLZIP_OPT_REMOVE_ALL_PATH,

    PCLZIP_CB_PRE_EXTRACT, 'myPreExtractCallBack') == 0) {

    die("Error : ".$archive->errorInfo(true));

    }

    }

    }`

    Work's fine for me, have fun.. ;)
    greetz esion

  • is the same function in 1.06 and i think it should work with version 1.06 too, just couldn't test it yet cause have to do a safemode-workaround before.. =)
  • 100% WORKING! :D
  • Do i have to CHMOD some Files? :-?
  • no you don't.. is chmodded 0777.. =)
  • It WORKS! Job Well Done! :)>-
  • My download link above is for version 1.05, and Fabrice's update (no longer online) for 1.06, but the fix works for all versions. (I just upgraded, so I needed the fix again...)

    Just paste the code below into your zen/functions.php file - place it at the very end of the file, just above the closing ?> - and that's all you need. No further downloads.

    ```

    // zip_open fix starts here

    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)

    {

    while ($s = fgets($res['fp'],1024)) {

    $data .= $s;

    }

    return $data;

    }

    function zip_entry_close(&$res)

    {

    fclose($res['fp']);

    unset($res['fp']);

    }

    function zip_close(&$fp)

    {

    fclose($fp['fp']);

    }

    `

    As mentioned above, there's more information on substituting zip_open by unzip in this way at http://php.net/zip_open

  • Iris, it looks like the community build, which will be released as 1.1 later this month is already using zip_open, check out line 463 in functions.php

    You can download the build here: http://www.zenphoto.org/files/nightly
  • Actually, it was the upgrading to the community build that had me coming back here for my own fix.

    But we must be talking about different nightlies... Would be great if for 1.1 uploading zips works on all hosts (also those that don't offer zip_open), straight out of the box. There will be many people who sooner give up on this fine gallery than fiddle with php files.

    aitf311 wrote:
    it looks like the community build [...] is already using zip_open,
    I assume this is a typo, because zenphoto has always used zip_open. That is the problem addressed in this topic: not all hosts have zip_open support. See first post in this topic for the resulting errors.
  • No typo, I just didnt understand what was being said. I got this into SVN 569 and seems to work well.
  • Perfect! Thanks!
  • I run my own apache server and have zip support in php5. Since revision 569 i get this error when accessing the gallery:

    `Fatal error: Cannot redeclare zip_open() in D:/htdocs/zenphoto/zen/functions.php on line 510`

    I'm a bit lost in this one, so... any clue?
  • Are you sure about the line number? In 569 the zip_open() declaration is on line 494. Seems like there is extra stuff in your version. Version 569 added that declaration (see above), so that's why you started seeing the message.

    I am guessing that your version of PHP won't let you over ride its zip_open function. Don't know why that would be, though.
  • I found it strange too that line number seemed wrong. line 510 is precisely the end of the function... who knows. The version I was using was the one in SVN (569), no added hacks.

    I have deactivated zip support and it is working fine without it. Maybe it would be good that someone confirms it is working ok in "zip-supported servers".
  • I think that the code was added for someone whose PHP did not have ZIP support. I am releasing a patch which will remove the code from functions.php to a file pclZip.php. Then functions.php will include that file if the zip_open() function is not defined. Should work, but since I don't get the error, I can't be sure.
  • I tried with and without zip support. I didn't get the error any more, i will try later to upload a zip in both modes.
Sign In or Register to comment.