Voting

: max(six, nine)?
(Example: nine)

The Note You're Voting On

bisqwit at iki dot fi
19 years ago
If your PHP installation does not have the zip_open function, and you can't install it for whatever reason, you can use these functions instead, if the server has access to the "unzip" utility (most Linux systems do).
So far I have tested these only in Fedora Core 3.
Use at your own risk.

<?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)
{
return
fread($res['fp'], $nbytes);
}
function
zip_entry_close(&$res)
{
fclose($res['fp']);
unset(
$res['fp']);
}
function
zip_close(&$fp)
{
fclose($fp['fp']);
}
?>

<< Back to user notes page

To Top