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.
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.
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)
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:
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.
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..
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.
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.
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.
Comments
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
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
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.
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
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
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
You can download the build here: http://www.zenphoto.org/files/nightly
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: 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.
`Fatal error: Cannot redeclare zip_open() in /htdocs/zenphoto/zen/functions.php on line 510`
I'm a bit lost in this one, so... any clue?
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 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".