When I try to upload a ZIP file through the admin interface, I get this error:
Quote:Fatal error: Call to undefined function: zip_open() in /home/myusername/public_html/chusy/pictures/zen/functions.php on line 102
What's wrong?
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 [i]changed[/i] only [i]added[/i], it shouldn't break anything.
More information on substituting zip_open by unzip at http://php.net/zip_open
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; $iextract( 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
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.
[b]aitf311 wrote:[/b]
Quote:[i]it looks like the community build [...] is already using zip_open,[/i]
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.
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.