r);
do
{
$path = @current($mypathdir);
@mkdir($path);
} while(@prev($mypathdir));
if($this->fp=@fopen($this->gzfilename,"w"))
{
return true;
}
return false;
}
//添加一个文件到 zip 压缩包中.
function addfile($data, $name)
{
$name = str_replace(''\\'', ''/'', $name);
if(strrchr($name,''/'')==''/'')
return $this->adddir($name);
if(!empty($this->filefilters))
{
if (!in_array(end(explode(".",$name)), $this->filefilters))
{
return;
}
}
$dtime = dechex($this->unix2DosTime());
$hexdtime = ''\x'' . $dtime . $dtime . ''\x'' . $dtime . $dtime . ''\x'' . $dtime . $dtime . ''\x'' . $dtime[0] . $dtime;
eval(''$hexdtime = "'' . $hexdtime . ''";'');
$unc_len = strlen($data);
$crc = crc32($data);
$zdata = gzcompress($data);
$c_len = strlen($zdata);
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
//新添文件内容格式化:
$datastr = "\x50\x4b\x03\x04";
$datastr .= "\x14\x00"; // ver needed to extract
$datastr .= "\x00\x00"; // gen purpose bit flag
$datastr .= "\x08\x00"; // compression method
$datastr .= $hexdtime; // last mod time and date
$datastr .= pack(''V'', $crc); // crc32
$datastr .= pack(''V'', $c_len); // compressed filesize
$datastr .= pack(''V'', $unc_len); // uncompressed filesize
$datastr .= pack(''v'', strlen($name)); // length of filename
$datastr .= pack(''v'', 0); // extra field length
$datastr .= $name;
$datastr .= $zdata;
$datastr .= pack(''V'', $crc); // crc32
$datastr .= pack(''V'', $c_len); // compressed filesize
$datastr .= pack(''V'', $unc_len); // uncompressed filesize
fwrite($this->fp,$datastr); //写入新的文件内容
$my_datastr_len = strlen($datastr);
unset($datastr);
//新添文件目录信息
$dirstr = "\x50\x4b\x01\x02";
$dirstr .= "\x00\x00"; // version made by
$dirstr .= "\x14\x00"; // version needed to extract
$dirstr .= "\x00\x00"; // gen purpose bit flag
$dirstr .= "\x08\x00"; // compression method
$dirstr .= $hexdtime; // last mod time & date
$dirstr .= pack(''V'', $crc); // crc32
$dirstr .= pack(''V'', $c_len); // compressed filesize
$dirstr .= pack(''V'', $unc_len); // uncompressed filesize
$dirstr .= pack(''v'', strlen($name) ); // length of filename
$dirstr .= pack(''v'', 0 ); // extra field length
$dirstr .= pack(''v'', 0 ); // file comment length
$dirstr .= pack(''v'', 0 ); // disk number start
$dirstr .= pack(''v'', 0 ); // internal file attributes
$dirstr .= pack(''V'', 32 ); // external file attributes - ''archive'' bit set
$dirstr .= pack(''V'',$this->datastr_len ); // relative offset of local header
$dirstr .= $name;
$this->dirstr .= $dirstr; //目录信息
$this -> file_count ++;
$this -> dirstr_len += strlen($dirstr);
$this -> datastr_len += $my_datastr_len;
}
function adddir($name)
{
$name = str_replace("\\", "/", $name);
$datastr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$datastr .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) );
$datastr .= pack("v", 0 ).$name.pack("V", 0).pack("V", 0).pack("V", 0);
fwrite($this->fp,$datastr); //写入新的文件内容
$