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

📄 pclzip.lib.php

📁 Joomla15 - 最新开源CMS
💻 PHP
📖 第 1 页 / 共 5 页
字号:
  $v_prop['comment'] = $v_central_dir['comment'];
  $v_prop['nb'] = $v_central_dir['entries'];
  $v_prop['status'] = 'ok';
}

// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop);
return $v_prop;
  }
  // --------------------------------------------------------------------------------

  // --------------------------------------------------------------------------------
  // Function : duplicate()
  // Description :
  //	This method creates an archive by copying the content of an other one. If
  //	the archive already exist, it is replaced by the new one without any warning.
  // Parameters :
  //	$p_archive : The filename of a valid archive, or
  //a valid PclZip object.
  // Return Values :
  //	1 on success.
  //	0 or a negative value on error (error code).
  // --------------------------------------------------------------------------------
  function duplicate($p_archive)
  {
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", "");
$v_result = 1;

// ----- Reset the error handler
$this->privErrorReset();

// ----- Look if the $p_archive is a PclZip object
if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
{
  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'");

  // ----- Duplicate the archive
  $v_result = $this->privDuplicate($p_archive->zipname);
}

// ----- Look if the $p_archive is a string (so a filename)
else if (is_string($p_archive))
{
  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'");

  // ----- Check that $p_archive is a valid zip file
  // TBC : Should also check the archive format
  if (!is_file($p_archive)) {
// ----- Error log
PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
$v_result = PCLZIP_ERR_MISSING_FILE;
  }
  else {
// ----- Duplicate the archive
$v_result = $this->privDuplicate($p_archive);
  }
}

// ----- Invalid variable
else
{
  // ----- Error log
  PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
  $v_result = PCLZIP_ERR_INVALID_PARAMETER;
}

// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
  }
  // --------------------------------------------------------------------------------

  // --------------------------------------------------------------------------------
  // Function : merge()
  // Description :
  //	This method merge the $p_archive_to_add archive at the end of the current
  //	one ($this).
  //	If the archive ($this) does not exist, the merge becomes a duplicate.
  //	If the $p_archive_to_add archive does not exist, the merge is a success.
  // Parameters :
  //	$p_archive_to_add : It can be directly the filename of a valid zip archive,
  //	or a PclZip object archive.
  // Return Values :
  //	1 on success,
  //	0 or negative values on error (see below).
  // --------------------------------------------------------------------------------
  function merge($p_archive_to_add)
  {
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", "");
$v_result = 1;

// ----- Reset the error handler
$this->privErrorReset();

// ----- Check archive
if (!$this->privCheckFormat()) {
  //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  return(0);
}

// ----- Look if the $p_archive_to_add is a PclZip object
if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
{
  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object");

  // ----- Merge the archive
  $v_result = $this->privMerge($p_archive_to_add);
}

// ----- Look if the $p_archive_to_add is a string (so a filename)
else if (is_string($p_archive_to_add))
{
  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename");

  // ----- Create a temporary archive
  $v_object_archive = new PclZip($p_archive_to_add);

  // ----- Merge the archive
  $v_result = $this->privMerge($v_object_archive);
}

// ----- Invalid variable
else
{
  // ----- Error log
  PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
  $v_result = PCLZIP_ERR_INVALID_PARAMETER;
}

// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
  }
  // --------------------------------------------------------------------------------



  // --------------------------------------------------------------------------------
  // Function : errorCode()
  // Description :
  // Parameters :
  // --------------------------------------------------------------------------------
  function errorCode()
  {
if (PCLZIP_ERROR_EXTERNAL == 1) {
  return(PclErrorCode());
}
else {
  return($this->error_code);
}
  }
  // --------------------------------------------------------------------------------

  // --------------------------------------------------------------------------------
  // Function : errorName()
  // Description :
  // Parameters :
  // --------------------------------------------------------------------------------
  function errorName($p_with_code=false)
  {
$v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
  PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
  PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
  PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
  PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
  PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
  PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
  PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
  PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
  PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
  PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
  PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
  PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
  PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
  PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
  PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
  PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE' );

if (isset($v_name[$this->error_code])) {
  $v_value = $v_name[$this->error_code];
}
else {
  $v_value = 'NoName';
}

if ($p_with_code) {
  return($v_value.' ('.$this->error_code.')');
}
else {
  return($v_value);
}
  }
  // --------------------------------------------------------------------------------

  // --------------------------------------------------------------------------------
  // Function : errorInfo()
  // Description :
  // Parameters :
  // --------------------------------------------------------------------------------
  function errorInfo($p_full=false)
  {
if (PCLZIP_ERROR_EXTERNAL == 1) {
  return(PclErrorString());
}
else {
  if ($p_full) {
return($this->errorName(true)." : ".$this->error_string);
  }
  else {
return($this->error_string." [code ".$this->error_code."]");
  }
}
  }
  // --------------------------------------------------------------------------------


// --------------------------------------------------------------------------------
// ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
// **********
// *****	THESES FUNCTIONS MUST NOT BE USED DIRECTLY	*****
// --------------------------------------------------------------------------------



  // --------------------------------------------------------------------------------
  // Function : privCheckFormat()
  // Description :
  //	This method check that the archive exists and is a valid zip archive.
  //	Several level of check exists. (futur)
  // Parameters :
  //	$p_level : Level of check. Default 0.
  //  0 : Check the first bytes (magic codes) (default value))
  //  1 : 0 + Check the central directory (futur)
  //  2 : 1 + Check each file header (futur)
  // Return Values :
  //	true on success,
  //	false on error, the error code is set.
  // --------------------------------------------------------------------------------
  function privCheckFormat($p_level=0)
  {
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", "");
$v_result = true;

	// ----- Reset the file system cache
clearstatcache();

// ----- Reset the error handler
$this->privErrorReset();

// ----- Look if the file exits
if (!is_file($this->zipname)) {
  // ----- Error log
  PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
  //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
  return(false);
}

// ----- Check that the file is readeable
if (!is_readable($this->zipname)) {
  // ----- Error log
  PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
  //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
  return(false);
}

// ----- Check the magic code
// TBC

// ----- Check the central header
// TBC

// ----- Check each file header
// TBC

// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
  }
  // --------------------------------------------------------------------------------

  // --------------------------------------------------------------------------------
  // Function : privParseOptions()
  // Description :
  //	This internal methods reads the variable list of arguments ($p_options_list,
  //	$p_size) and generate an array with the options and values ($v_result_list).
  //	$v_requested_options contains the options that can be present and those that
  //	must be present.
  //	$v_requested_options is an array, with the option value as key, and 'optional',
  //	or 'mandatory' as value.
  // Parameters :
  //	See above.
  // Return Values :
  //	1 on success.
  //	0 on failure.
  // --------------------------------------------------------------------------------
  function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
  {
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", "");
$v_result=1;

// ----- Read the options
$i=0;
while ($i<$p_size) {
  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'");

  // ----- Check if the option is requested
  if (!isset($v_requested_options[$p_options_list[$i]])) {
// ----- Error log
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");

// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
return PclZip::errorCode();
  }

  // ----- Look for next option
  switch ($p_options_list[$i]) {
// ----- Look for options that request a path value
case PCLZIP_OPT_PATH :
case PCLZIP_OPT_REMOVE_PATH :
case PCLZIP_OPT_ADD_PATH :
  // ----- Check the number of parameters
  if (($i+1) >= $p_size) {
// ----- Error log
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");

// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
return PclZip::errorCode();
  }

  // ----- Get the value
  $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);
  //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
  $i++;
break;

// ----- Look for options that request an array of string for value
case PCLZIP_OPT_BY_NAME :
  // ----- Check the number of parameters
  if (($i+1) >= $p_size) {
// ----- Error log
PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");

// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
return PclZip::errorCode();
  }

  // ----- Get the value
  if (is_string($p_options_list[$i+1])) {
  $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
  }
  else if (is_array($p_options_list[$i+1])) {
  $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
  }
  else {

⌨️ 快捷键说明

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