Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: zip_open - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net

search for in the

zip_read" width="11" height="7"/> <zip_entry_read
Last updated: Wed, 01 Nov 2006
view this page in

zip_open

(PHP 4 >= 4.1.0, PECL)

zip_open -- Zip ファイルアーカイブをオープンする

説明

mixed zip_open ( string filename )

読み込み用に新規に Zip アーカイブをオープンします。

パラメータ

filename

オープンする ZIP アーカイブのファイル名。

返り値

後で zip_read() および zip_close() で使用されるリソースハンドル、または、 filename が存在しない場合やその他のエラーが発生した場合は エラーの番号を返します。



add a note add a note User Contributed Notes
zip_open
Michael
09-Jun-2006 05:55
I tried the replacement hack above on Windows2k, here
are some fixes needed:
replace:
  return "'".str_replace("'", "'\''", $s)."'";
with:
  return '"'.str_replace("'", "'\''", $s).'"';

replace:
if($line[0]=='-') { $ok=!$ok; continue; }
with:
if($line[2]=='-') { $ok=!$ok; continue; }

replace:
 $contents[] = Array('name' => $fn, 'length' => $length);
with:
   array_push($contents, Array('name' => $fn, 'length' => $length));
ponsho
14-Dec-2005 05:44
For bisqwit at iki dot fi solution of alternative functions there's just one problem when trying to read the file thats because some bug in fread when handling from popen so it just load 8192 bytes here's the function corrected.

<?php

  
function zip_entry_read(&$res, $nbytes)
   {
     while (
$s = fgets($res['fp'],1024)) {
    
$data  .= $s;
     }
     return
$data;
   }
?>
barbarinasv at interfree dot it
05-Oct-2005 05:02
Function zip_entry_read() written by "bisqwit at iki dot fi" has to be modified to read entire files:

<?php
function zip_entry_read(&$res, $nbytes) {
   while (!
feof($res['fp'])) {
      
$contents .= fread($res['fp'], $nbytes);
   }
   return
$contents;
}
?>
robert at cotran dot ca
22-Sep-2005 04:19
The zip_entry_read above is wrong.  Since the file was opened with popen, you have to read the file in chunks, so zip_entry_read should read:

function zip_entry_read(&$res, $nbytes)
{
   $contents = '';
   while (!feof($res['fp'])) {
       $contents .= fread($res['fp'], 8192);
   }
   return $contents;
}

Otherwise, it was a very useful library.  Thanks!
bisqwit at iki dot fi
02-Sep-2005 08:08
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']);
}
?>
ajbaas at cs dot uu dot nl
14-Oct-2004 04:08
note: if you are using PHP in module mode, the open_zip function will need an absolute path to the file, because it is not aware of it's whereabouts. this is for win32 at least.

zip_read" width="11" height="7"/> <zip_entry_read
Last updated: Wed, 01 Nov 2006
 
 
show source | credits | sitemap | contact | advertising | mirror sites