程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php 文件在線解壓代碼

php 文件在線解壓代碼

編輯:關於PHP編程

public function ExtractFile($header,$to,$zip) {
  $header = $this->readfileheader($zip);

  if (substr($to,-1)!="/") $to.="/";
  if ($to=='./') $to = '';
  $pth = explode("/",$to.$header['filename']);
  $mydir = '';
  for($i=0;$i<count($pth)-1;$i++) {
   if (!$pth[$i]) continue;
   $mydir .= $pth[$i]."/";
   if ((!is_dir($mydir) && @mkdir($mydir,0777)) || (($mydir==$to.$header['filename'] || ($mydir==$to && $this->total_folders==0)) && is_dir($mydir)) ) {
    @chmod($mydir,0777);
    $this->total_folders ++;
    echo 'Extract : ',$mydir,'<br>';
   }
  }

  if (strrchr($header['filename'],'/')=='/') return;
  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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved