⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pclzip.php

📁 php版wap手机网站源码(英语) the best wap scripts from
💻 PHP
📖 第 1 页 / 共 5 页
字号:
  $v_data = unpack('Vid', $v_binary_data);
  if ($v_data['id'] != 0x04034b50)
 {
  PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
  return PclZip::errorCode();
 }
 $v_binary_data = fread($this->zip_fd, 26);
 if (strlen($v_binary_data) != 26)
 {
 $p_header['filename'] = "";
 $p_header['status'] = "invalid_header";
  PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
  return PclZip::errorCode();
 }
   $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
  $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
   if ($v_data['extra_len'] != 0) {
 $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
 }
 else {
 $p_header['extra'] = '';
 }
  $p_header['version_extracted'] = $v_data['version'];
  $p_header['compression'] = $v_data['compression'];
  $p_header['size'] = $v_data['size'];
  $p_header['compressed_size'] = $v_data['compressed_size'];
  $p_header['crc'] = $v_data['crc'];
  $p_header['flag'] = $v_data['flag'];
  $p_header['mdate'] = $v_data['mdate'];
 $p_header['mtime'] = $v_data['mtime'];
 if ($p_header['mdate'] && $p_header['mtime'])
 {
 $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
 $v_seconde = ($p_header['mtime'] & 0x001F)*2;
 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
 $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
 $v_day = $p_header['mdate'] & 0x001F;
 $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
  }
 else
 {
 $p_header['mtime'] = time();
  }
 $p_header['stored_filename'] = $p_header['filename'];
 $p_header['status'] = "ok";
  return $v_result;
 }
 function privReadCentralFileHeader(&$p_header)
 {
  $v_result=1;
 $v_binary_data = @fread($this->zip_fd, 4);
  $v_data = unpack('Vid', $v_binary_data);
  if ($v_data['id'] != 0x02014b50)
 {
  PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
  return PclZip::errorCode();
 }
 $v_binary_data = fread($this->zip_fd, 42);
 if (strlen($v_binary_data) != 42)
 {
 $p_header['filename'] = "";
 $p_header['status'] = "invalid_header";
  PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
  return PclZip::errorCode();
 }
   $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
  if ($p_header['filename_len'] != 0)
 $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
 else
 $p_header['filename'] = '';
   if ($p_header['extra_len'] != 0)
 $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
 else
 $p_header['extra'] = '';
   if ($p_header['comment_len'] != 0)
 $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
 else
 $p_header['comment'] = '';
         if ($p_header['mdate'] && $p_header['mtime'])
 {
 $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
 $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
 $v_seconde = ($p_header['mtime'] & 0x001F)*2;
 $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
 $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
 $v_day = $p_header['mdate'] & 0x001F;
 $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
  }
 else
 {
 $p_header['mtime'] = time();
  }
 $p_header['stored_filename'] = $p_header['filename'];
 $p_header['status'] = 'ok';
   if (substr($p_header['filename'], -1) == '/') {
 $p_header['external'] = 0x00000010;
  }
   return $v_result;
 }
 function privCheckFileHeaders(&$p_local_header, &$p_central_header)
 {
  $v_result=1;
	if ($p_local_header['filename'] != $p_central_header['filename']) {
 	}
	if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
 	}
	if ($p_local_header['flag'] != $p_central_header['flag']) {
 	}
	if ($p_local_header['compression'] != $p_central_header['compression']) {
 	}
	if ($p_local_header['mtime'] != $p_central_header['mtime']) {
 	}
	if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
 	}
	if (($p_local_header['flag'] & 8) == 8) {
   $p_local_header['size'] = $p_central_header['size'];
  $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
  $p_local_header['crc'] = $p_central_header['crc'];
 	}
  return $v_result;
 }
 function privReadEndCentralDir(&$p_central_dir)
 {
  $v_result=1;
 $v_size = filesize($this->zipname);
  @fseek($this->zip_fd, $v_size);
  if (@ftell($this->zip_fd) != $v_size)
 {
 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
  return PclZip::errorCode();
 }
 $v_found = 0;
 if ($v_size > 26) {
  @fseek($this->zip_fd, $v_size-22);
  if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
 {
 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
  return PclZip::errorCode();
 }
 $v_binary_data = @fread($this->zip_fd, 4);
  $v_data = @unpack('Vid', $v_binary_data);
  if ($v_data['id'] == 0x06054b50) {
  $v_found = 1;
 }
 $v_pos = ftell($this->zip_fd);
 }
 if (!$v_found) {
  $v_maximum_size = 65557;
 if ($v_maximum_size > $v_size)
 $v_maximum_size = $v_size;
 @fseek($this->zip_fd, $v_size-$v_maximum_size);
 if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
 {
 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
  return PclZip::errorCode();
 }
  $v_pos = ftell($this->zip_fd);
 $v_bytes = 0x00000000;
 while ($v_pos < $v_size)
 {
 $v_byte = @fread($this->zip_fd, 1);
 $v_bytes = ($v_bytes << 8) | Ord($v_byte);
 if ($v_bytes == 0x504b0506)
 {
  $v_pos++;
 break;
 }
 $v_pos++;
 }
 if ($v_pos == $v_size)
 {
  PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
  return PclZip::errorCode();
 }
 }
 $v_binary_data = fread($this->zip_fd, 18);
 if (strlen($v_binary_data) != 18)
 {
  PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
  return PclZip::errorCode();
 }
 $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
  if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
 	 if (0) {
 PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
	 'The central dir is not at the end of the archive.'
						 .' Some trailing bytes exists after the archive.');
  return PclZip::errorCode();
	 }
 }
 if ($v_data['comment_size'] != 0)
 $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
 else
 $p_central_dir['comment'] = '';
  $p_central_dir['entries'] = $v_data['entries'];
  $p_central_dir['disk_entries'] = $v_data['disk_entries'];
  $p_central_dir['offset'] = $v_data['offset'];
  $p_central_dir['size'] = $v_data['size'];
  $p_central_dir['disk'] = $v_data['disk'];
  $p_central_dir['disk_start'] = $v_data['disk_start'];
   return $v_result;
 }
 function privDeleteByRule(&$p_result_list, &$p_options)
 {
  $v_result=1;
 $v_list_detail = array();
  if (($v_result=$this->privOpenFd('rb')) != 1)
 {
  return $v_result;
 }
 $v_central_dir = array();
 if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
 {
 $this->privCloseFd();
  return $v_result;
 }
  @rewind($this->zip_fd);
  $v_pos_entry = $v_central_dir['offset'];
  @rewind($this->zip_fd);
  if (@fseek($this->zip_fd, $v_pos_entry))
 {
 $this->privCloseFd();
 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  return PclZip::errorCode();
 }
  $v_header_list = array();
 $j_start = 0;
 for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
 {
  $v_header_list[$v_nb_extracted] = array();
 if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
 {
 $this->privCloseFd();
  return $v_result;
 }
  $v_header_list[$v_nb_extracted]['index'] = $i;
 $v_found = false;
 if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
 && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
  for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
  if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
  if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
 && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
  $v_found = true;
 }
 elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010)
 && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
  $v_found = true;
 }
 }
 elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
  $v_found = true;
 }
 }
 }
 else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
 && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
  if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
  $v_found = true;
 }
 }
 else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
 && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
  if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
  $v_found = true;
 }
 }
 else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
 && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
  for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
  if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
  $v_found = true;
 }
 if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
  $j_start = $j+1;
 }
 if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
  break;
 }
 }
 }
 if ($v_found)
 {
  unset($v_header_list[$v_nb_extracted]);
 }
 else
 {
  $v_nb_extracted++;
 }
 }
 if ($v_nb_extracted > 0) {
 $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
 $v_temp_zip = new PclZip($v_zip_temp_name);
  if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
 $this->privCloseFd();
  return $v_result;
 }
 for ($i=0; $i<sizeof($v_header_list); $i++) {
    @rewind($this->zip_fd);
  if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
 $this->privCloseFd();
 $v_temp_zip->privCloseFd();
 @unlink($v_zip_temp_name);
 PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  return PclZip::errorCode();
 }
  $v_local_header = array();
 if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
 $this->privCloseFd();
 $v_temp_zip->privCloseFd();
 @unlink($v_zip_temp_name);
  return $v_result;
 }
 if ($this->privCheckFileHeaders($v_local_header,
			 $v_header_list[$i]) != 1) {
 }
 unset($v_local_header);
 if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
 $this->privCloseFd();
 $v_temp_zip->privCloseFd();
 @unlink($v_zip_temp_name);
  return $v_result;
 }
  if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
 $this->privCloseFd();
 $v_temp_zip->privCloseFd();
 @unlink($v_zip_temp_name);
  return $v_result;
 }
 }
 $v_offset = @ftell($v_temp_zip->zip_fd);
   for ($i=0; $i<sizeof($v_header_list); $i++) {
  if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
 $v_temp_zip->privCloseFd();
 $this->privCloseFd();
 @unlink($v_zip_temp_name);
  return $v_result;
 }
 $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
 }
  $v_comment = '';
 if (isset($p_options[PCLZIP_OPT_COMMENT])) {
 $v_comment = $p_options[PCLZIP_OPT_COMMENT];
 }
 $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
 if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
 unset($v_header_list);
 $v_temp_zip->privCloseFd();
 $this->privCloseFd();
 @unlink($v_zip_temp_name);
  return $v_result;
 }
 $v_temp_zip->privCloseFd();
 $this->privCloseFd();
 @unlink($this->zipname);
 PclZipUtilRename($v_zip_temp_name, $this->zipname);
 unset($v_temp_zip);
 }
 else if ($v_central_dir['entries'] != 0) {
 $this->privCloseFd();
 if (($v_result = $this->privOpenFd('wb')) != 1) {
  return $v_result;
 }
 if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
  return $v_result;
 }
 $this->privCloseFd();
 }
  return $v_result;
 }
 function privDirCheck($p_dir, $p_is_dir=false)
 {
 $v_result = 1;
  if (($p_is_dir) && (substr($p_dir, -1)=='/'))
 {
 $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
 }
  if ((is_dir($p_dir)) || ($p_dir == ""))
 {
  return 1;
 }
 $p_parent_dir = dirname($p_dir);
  if ($p_parent_dir != $p_dir)
 {
 if ($p_parent_dir != "")
 {
 if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
 {
  return $v_result;
 }
 }
 }
  if (!@mkdir($p_dir, 0777))
 {
 PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
  return PclZip::errorCode();
 }
  return $v_result;
 }
 function privMerge(&$p_archive_to_add)
 {
  $v_result=1;
 if (!is_file($p_archive_to_add->zipname))
 {
  $v_res

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -