• [织梦吧]唯一域名:www.dedecms8.com,织梦DedeCMS学习平台.

当前位置: > 编程与数据库 > php编程 >

PHP解压ZIP的一个类(3)

来源: www.dedecms8.com 编辑:织梦吧 时间:2012-02-07点击:

  {

  $hour = ($header['mtime'] & 0xF800) >> 11;

  $minute = ($header['mtime'] & 0x07E0) >> 5;

  $seconde = ($header['mtime'] & 0x001F)*2;

  $year = (($header['mdate'] & 0xFE00) >> 9) + 1980;

  $month = ($header['mdate'] & 0x01E0) >> 5;

  $day = $header['mdate'] & 0x001F;

  $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);

  } else {

  $header['mtime'] = time();

  }

  $header['stored_filename'] = $header['filename'];

  $header['status'] = 'ok';

  if (substr($header['filename'], -1) == '/')

  $header['external'] = 0x41FF0010;

  return $header;

  }

  function ReadCentralDir($zip,$zip_name)

  {

  $size = filesize($zip_name);

  if ($size < 277) $maximum_size = $size;

  else $maximum_size=277;

  @fseek($zip, $size-$maximum_size);

  $pos = ftell($zip); $bytes = 0x00000000;

  while ($pos < $size)

  {

  $byte = @fread($zip, 1); $bytes=($bytes << 8) | Ord($byte);

  if ($bytes == 0x504b0506){ $pos++; break; } $pos++;

  }

  $data=unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size',fread($zip,18));

  if ($data['comment_size'] != 0)

  $centd['comment'] = fread($zip, $data['comment_size']);

  else $centd['comment'] = ''; $centd['entries'] = $data['entries'];

  $centd['disk_entries'] = $data['disk_entries'];

  $centd['offset'] = $data['offset'];$centd['disk_start'] = $data['disk_start'];

  $centd['size'] = $data['size']; $centd['disk'] = $data['disk'];

  return $centd;

  }

  function ExtractFile($header,$to,$zip)

  {

  $header = $this->readfileheader($zip);

  if(substr($to,-1)!="/") $to.="/";

  if(!@is_dir($to)) @mkdir($to,0777);

  $pth = explode("/",dirname($header['filename']));

  for($i=0;isset($pth[$i]);$i++){

  if(!$pth[$i]) continue;$pthss.=$pth[$i]."/";

  if(!is_dir($to.$pthss)) @mkdir($to.$pthss,0777);

  }

  if (!($header['external']==0x41FF0010)&&!($header['external']==16))

  {

  if ($header['compression']==0)

  {

  $fp = @fopen($to.$header['filename'], 'wb');

  if(!$fp) return(-1);

  $size = $header['compressed_size'];

  while ($size != 0)

  {

  $read_size = ($size < 2048 ? $size : 2048);

  $buffer = fread($zip, $read_size);

  $binary_data = pack('a'.$read_size, $buffer);

  @fwrite($fp, $binary_data, $read_size);

  $size -= $read_size;

  }

  fclose($fp);

  touch($to.$header['filename'], $header['mtime']);

  }else{

  $fp = @fopen($to.$header['filename'].'.gz','wb');

  if(!$fp) return(-1);

  $binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']),

  Chr(0x00), time(), Chr(0x00), Chr(3));

  fwrite($fp, $binary_data, 10);

  $size = $header['compressed_size'];

  while ($size != 0)

  {

  $read_size = ($size < 1024 ? $size : 1024);

  $buffer = fread($zip, $read_size);

  $binary_data = pack('a'.$read_size, $buffer);

  @fwrite($fp, $binary_data, $read_size);

  $size -= $read_size;

  }

  $binary_data = pack('VV', $header['crc'], $header['size']);

  fwrite($fp, $binary_data,8); fclose($fp);

  $gzp = @gzopen($to.$header['filename'].'.gz','rb') or die("Cette archive est compress閑");

  if(!$gzp) return(-2);

  $fp = @fopen($to.$header['filename'],'wb');

  if(!$fp) return(-1);

  $size = $header['size'];

  while ($size != 0)

  {

  $read_size = ($size < 2048 ? $size : 2048);

  $buffer = gzread($gzp, $read_size);

  $binary_data = pack('a'.$read_size, $buffer);

  @fwrite($fp, $binary_data, $read_size);

  $size -= $read_size;

  }

  fclose($fp); gzclose($gzp);

  touch($to.$header['filename'], $header['mtime']);

  @unlink($to.$header['filename'].'.gz');

标签: php zip 解压

About D8

  • ©2014 织梦吧(d8) DedeCMS学习交流平台
  • 唯一网址 www.DedeCMS8.com 网站地图
  • 联系我们 1170734538@qq.com ,  QQ