本文整理汇总了PHP中PclZipUtilPathInclusion函数的典型用法代码示例。如果您正苦于以下问题:PHP PclZipUtilPathInclusion函数的具体用法?PHP PclZipUtilPathInclusion怎么用?PHP PclZipUtilPathInclusion使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PclZipUtilPathInclusion函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: privExtractFile
function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
{
$v_result = 1;
// ----- Read the file header
if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
// ----- Return
return $v_result;
}
// ----- Check that the file header is coherent with $p_entry info
if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
// TBC
}
// ----- Look for all path to remove
if ($p_remove_all_path == true) {
// ----- Look for folder entry that not need to be extracted
if (($p_entry['external'] & 0x10) == 0x10) {
$p_entry['status'] = "filtered";
return $v_result;
}
// ----- Get the basename of the path
$p_entry['filename'] = basename($p_entry['filename']);
} else {
if ($p_remove_path != "") {
if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) {
// ----- Change the file status
$p_entry['status'] = "filtered";
// ----- Return
return $v_result;
}
$p_remove_path_size = strlen($p_remove_path);
if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) {
// ----- Remove the path
$p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
}
}
}
// ----- Add the path
if ($p_path != '') {
$p_entry['filename'] = $p_path . "/" . $p_entry['filename'];
}
// ----- Check a base_dir_restriction
if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
$v_inclusion = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], $p_entry['filename']);
if ($v_inclusion == 0) {
PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, "Filename '" . $p_entry['filename'] . "' is " . "outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
return PclZip::errorCode();
}
}
// ----- Look for pre-extract callback
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
// ----- Generate a local information
$v_local_header = array();
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
// ----- Call the callback
// Here I do not use call_user_func() because I need to send a reference to the
// header.
// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
$v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
if ($v_result == 0) {
// ----- Change the file status
$p_entry['status'] = "skipped";
$v_result = 1;
}
// ----- Look for abort result
if ($v_result == 2) {
// ----- This status is internal and will be changed in 'skipped'
$p_entry['status'] = "aborted";
$v_result = PCLZIP_ERR_USER_ABORTED;
}
// ----- Update the informations
// Only some fields can be modified
$p_entry['filename'] = $v_local_header['filename'];
}
// ----- Look if extraction should be done
if ($p_entry['status'] == 'ok') {
// ----- Look for specific actions while the file exist
if (file_exists($p_entry['filename'])) {
// ----- Look if file is a directory
if (is_dir($p_entry['filename'])) {
// ----- Change the file status
$p_entry['status'] = "already_a_directory";
// ----- Look for PCLZIP_OPT_STOP_ON_ERROR
// For historical reason first PclZip implementation does not stop
// when this kind of error occurs.
if (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]) && $p_options[PCLZIP_OPT_STOP_ON_ERROR] === true) {
PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, "Filename '" . $p_entry['filename'] . "' is " . "already used by an existing directory");
return PclZip::errorCode();
}
} else {
if (!is_writeable($p_entry['filename'])) {
// ----- Change the file status
$p_entry['status'] = "write_protected";
// ----- Look for PCLZIP_OPT_STOP_ON_ERROR
// For historical reason first PclZip implementation does not stop
// when this kind of error occurs.
if (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]) && $p_options[PCLZIP_OPT_STOP_ON_ERROR] === true) {
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, "Filename '" . $p_entry['filename'] . "' exists " . "and is write protected");
return PclZip::errorCode();
}
} else {
//.........这里部分代码省略.........
示例2: privExtractFile
function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
{
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");
$v_result = 1;
// ----- Read the file header
if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");
// ----- Check that the file header is coherent with $p_entry info
if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
// TBC
}
// ----- Look for all path to remove
if ($p_remove_all_path == true) {
// ----- Look for folder entry that not need to be extracted
if (($p_entry['external'] & 0x10) == 0x10) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The entry is a folder : need to be filtered");
$p_entry['status'] = "filtered";
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "All path is removed");
// ----- Get the basename of the path
$p_entry['filename'] = basename($p_entry['filename']);
} else {
if ($p_remove_path != "") {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Look for some path to remove");
if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '".$p_entry['filename']."'");
// ----- Change the file status
$p_entry['status'] = "filtered";
// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
$p_remove_path_size = strlen($p_remove_path);
if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '".$p_entry['filename']."'");
// ----- Remove the path
$p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '".$p_entry['filename']."'");
}
}
}
// ----- Add the path
if ($p_path != '') {
$p_entry['filename'] = $p_path . "/" . $p_entry['filename'];
}
// ----- Check a base_dir_restriction
if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Check the extract directory restriction");
$v_inclusion = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], $p_entry['filename']);
if ($v_inclusion == 0) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "PCLZIP_OPT_EXTRACT_DIR_RESTRICTION is selected, file is outside restriction");
PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, "Filename '" . $p_entry['filename'] . "' is " . "outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
return PclZip::errorCode();
}
}
// ----- Look for pre-extract callback
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction");
// ----- Generate a local information
$v_local_header = array();
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
// ----- Call the callback
// Here I do not use call_user_func() because I need to send a reference to the
// header.
eval('$v_result = ' . $p_options[PCLZIP_CB_PRE_EXTRACT] . '(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
if ($v_result == 0) {
// ----- Change the file status
$p_entry['status'] = "skipped";
$v_result = 1;
}
// ----- Look for abort result
if ($v_result == 2) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
// ----- This status is internal and will be changed in 'skipped'
$p_entry['status'] = "aborted";
$v_result = PCLZIP_ERR_USER_ABORTED;
}
// ----- Update the informations
// Only some fields can be modified
$p_entry['filename'] = $v_local_header['filename'];
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");
}
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");
// ----- Look if extraction should be done
if ($p_entry['status'] == 'ok') {
// ----- Look for specific actions while the file exist
if (file_exists($p_entry['filename'])) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_entry['filename']."' already exists");
// ----- Look if file is a directory
if (is_dir($p_entry['filename'])) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is a directory");
// ----- Change the file status
$p_entry['status'] = "already_a_directory";
//.........这里部分代码省略.........
示例3: privExtractFile
function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
{
//--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='$p_path', remove_path='$p_remove_path', remove_all_path='".($p_remove_all_path?'true':'false')."'");
$v_result = 1;
// ----- Read the file header
if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '".$v_header['filename']."', size '".$v_header['size']."'");
// ----- Check that the file header is coherent with $p_entry info
// TBC
// ----- Look for all path to remove
if ($p_remove_all_path == true) {
// ----- Get the basename of the path
$p_entry['filename'] = basename($p_entry['filename']);
} else {
if ($p_remove_path != "") {
//if (strcmp($p_remove_path, $p_entry['filename'])==0)
if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '".$p_entry['filename']."'");
// ----- Change the file status
$p_entry['status'] = "filtered";
// ----- Return
//--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
$p_remove_path_size = strlen($p_remove_path);
if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '".$p_entry['filename']."'");
// ----- Remove the path
$p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '".$p_entry['filename']."'");
}
}
}
// ----- Add the path
if ($p_path != '') {
$p_entry['filename'] = $p_path . "/" . $p_entry['filename'];
}
// ----- Look for pre-extract callback
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '".$p_options[PCLZIP_CB_PRE_EXTRACT]."()') is defined for the extraction");
// ----- Generate a local information
$v_local_header = array();
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
// ----- Call the callback
// Here I do not use call_user_func() because I need to send a reference to the
// header.
eval('$v_result = ' . $p_options[PCLZIP_CB_PRE_EXTRACT] . '(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
if ($v_result == 0) {
// ----- Change the file status
$p_entry['status'] = "skipped";
$v_result = 1;
}
// ----- Look for abort result
if ($v_result == 2) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "User callback abort the extraction");
// ----- This status is internal and will be changed in 'skipped'
$p_entry['status'] = "aborted";
$v_result = PCLZIP_ERR_USER_ABORTED;
}
// ----- Update the informations
// Only some fields can be modified
$p_entry['filename'] = $v_local_header['filename'];
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '".$p_entry['filename']."'");
}
// ----- Trace
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '".$p_entry['filename']."', size '$v_header[size]'");
// ----- Look if extraction should be done
if ($p_entry['status'] == 'ok') {
// ----- Look for specific actions while the file exist
if (file_exists($p_entry['filename'])) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "File '".$p_entry['filename']."' already exists");
// ----- Look if file is a directory
if (is_dir($p_entry['filename'])) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is a directory");
// ----- Change the file status
$p_entry['status'] = "already_a_directory";
// ----- Return
////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
//return $v_result;
} else {
if (!is_writeable($p_entry['filename'])) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is write protected");
// ----- Change the file status
$p_entry['status'] = "write_protected";
// ----- Return
////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
//return $v_result;
} else {
if (filemtime($p_entry['filename']) > $p_entry['mtime']) {
//--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '".$p_entry['filename']."' is newer (".date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])).") than the extracted file (".date("l dS of F Y h:i:s A", $p_entry['mtime']).")");
// ----- Change the file status
$p_entry['status'] = "newer_exist";
// ----- Return
////--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
//return $v_result;
}
//.........这里部分代码省略.........
示例4: privExtractFile
function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
{
$v_result = 1;
if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
return $v_result;
}
if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
}
if ($p_remove_all_path == true) {
if (($p_entry['external'] & 0x10) == 0x10) {
$p_entry['status'] = "filtered";
return $v_result;
}
$p_entry['filename'] = basename($p_entry['filename']);
} else {
if ($p_remove_path != "") {
if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) {
$p_entry['status'] = "filtered";
return $v_result;
}
$p_remove_path_size = strlen($p_remove_path);
if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) {
$p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
}
}
}
if ($p_path != '') {
$p_entry['filename'] = $p_path . "/" . $p_entry['filename'];
}
if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
$v_inclusion = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], $p_entry['filename']);
if ($v_inclusion == 0) {
PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, "Filename '" . $p_entry['filename'] . "' is " . "outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
return PclZip::errorCode();
}
}
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
$v_local_header = array();
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
eval('$v_result = ' . $p_options[PCLZIP_CB_PRE_EXTRACT] . '(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
if ($v_result == 0) {
$p_entry['status'] = "skipped";
$v_result = 1;
}
if ($v_result == 2) {
$p_entry['status'] = "aborted";
$v_result = PCLZIP_ERR_USER_ABORTED;
}
$p_entry['filename'] = $v_local_header['filename'];
}
if ($p_entry['status'] == 'ok') {
if (file_exists($p_entry['filename'])) {
if (is_dir($p_entry['filename'])) {
$p_entry['status'] = "already_a_directory";
if (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]) && $p_options[PCLZIP_OPT_STOP_ON_ERROR] === true) {
PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, "Filename '" . $p_entry['filename'] . "' is " . "already used by an existing directory");
return PclZip::errorCode();
}
} else {
if (!is_writeable($p_entry['filename'])) {
$p_entry['status'] = "write_protected";
if (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]) && $p_options[PCLZIP_OPT_STOP_ON_ERROR] === true) {
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, "Filename '" . $p_entry['filename'] . "' exists " . "and is write protected");
return PclZip::errorCode();
}
} else {
if (filemtime($p_entry['filename']) > $p_entry['mtime']) {
if (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]) && $p_options[PCLZIP_OPT_REPLACE_NEWER] === true) {
} else {
$p_entry['status'] = "newer_exist";
if (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]) && $p_options[PCLZIP_OPT_STOP_ON_ERROR] === true) {
PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, "Newer version of '" . $p_entry['filename'] . "' exists " . "and option PCLZIP_OPT_REPLACE_NEWER is not selected");
return PclZip::errorCode();
}
}
} else {
}
}
}
} else {
if (($p_entry['external'] & 0x10) == 0x10 || substr($p_entry['filename'], -1) == '/') {
$v_dir_to_check = $p_entry['filename'];
} else {
if (!strstr($p_entry['filename'], "/")) {
$v_dir_to_check = "";
} else {
$v_dir_to_check = dirname($p_entry['filename']);
}
}
if (($v_result = $this->privDirCheck($v_dir_to_check, ($p_entry['external'] & 0x10) == 0x10)) != 1) {
$p_entry['status'] = "path_creation_fail";
$v_result = 1;
}
}
}
if ($p_entry['status'] == 'ok') {
if (!(($p_entry['external'] & 0x10) == 0x10)) {
if ($p_entry['compression'] == 0) {
if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
$p_entry['status'] = "write_error";
//.........这里部分代码省略.........
示例5: privExtractFile
function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
{
PclTraceFctStart(__FILE__, __LINE__, 'PclZip::privExtractFile', "path='{$p_path}', remove_path='{$p_remove_path}', remove_all_path='" . ($p_remove_all_path ? 'true' : 'false') . "'");
$v_result = 1;
// ----- Read the file header
if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
// ----- Return
PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
PclTraceFctMessage(__FILE__, __LINE__, 2, "Found file '" . $v_header['filename'] . "', size '" . $v_header['size'] . "'");
// ----- Check that the file header is coherent with $p_entry info
// TBC
// ----- Look for all path to remove
if ($p_remove_all_path == true) {
// ----- Get the basename of the path
$p_entry['filename'] = basename($p_entry['filename']);
} else {
if ($p_remove_path != "") {
//if (strcmp($p_remove_path, $p_entry['filename'])==0)
if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) {
PclTraceFctMessage(__FILE__, __LINE__, 2, "The folder is the same as the removed path '" . $p_entry['filename'] . "'");
// ----- Change the file status
$p_entry['status'] = "filtered";
// ----- Return
PclTraceFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
$p_remove_path_size = strlen($p_remove_path);
if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) {
PclTraceFctMessage(__FILE__, __LINE__, 3, "Found path '{$p_remove_path}' to remove in file '" . $p_entry['filename'] . "'");
// ----- Remove the path
$p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
PclTraceFctMessage(__FILE__, __LINE__, 3, "Resulting file is '" . $p_entry['filename'] . "'");
}
}
}
// ----- Add the path
if ($p_path != '') {
$p_entry['filename'] = $p_path . "/" . $p_entry['filename'];
}
// ----- Look for pre-extract callback
if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
PclTraceFctMessage(__FILE__, __LINE__, 2, "A pre-callback '" . $p_options[PCLZIP_CB_PRE_EXTRACT] . "()') is defined for the extraction");
// ----- Generate a local information
$v_local_header = array();
$this->privConvertHeader2FileInfo($p_entry, $v_local_header);
// ----- Call the callback
// Here I do not use call_user_func() because I need to send a reference to the
// header.
eval('$v_result = ' . $p_options[PCLZIP_CB_PRE_EXTRACT] . '(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
if ($v_result == 0) {
// ----- Change the file status
$p_entry['status'] = "skipped";
}
// ----- Update the informations
// Only some fields can be modified
$p_entry['filename'] = $v_local_header['filename'];
PclTraceFctMessage(__FILE__, __LINE__, 2, "New filename is '" . $p_entry['filename'] . "'");
}
// ----- Trace
PclTraceFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '" . $p_entry['filename'] . "', size '{$v_header['size']}'");
// ----- Look if extraction should be done
if ($p_entry['status'] == 'ok') {
// ----- Look for specific actions while the file exist
if (file_exists($p_entry['filename'])) {
PclTraceFctMessage(__FILE__, __LINE__, 2, "File '" . $p_entry['filename'] . "' already exists");
// ----- Look if file is a directory
if (is_dir($p_entry['filename'])) {
PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '" . $p_entry['filename'] . "' is a directory");
// ----- Change the file status
$p_entry['status'] = "already_a_directory";
// ----- Return
//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
//return $v_result;
} else {
if (!is_writeable($p_entry['filename'])) {
PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '" . $p_entry['filename'] . "' is write protected");
// ----- Change the file status
$p_entry['status'] = "write_protected";
// ----- Return
//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
//return $v_result;
} else {
if (filemtime($p_entry['filename']) > $p_entry['mtime']) {
PclTraceFctMessage(__FILE__, __LINE__, 2, "Existing file '" . $p_entry['filename'] . "' is newer (" . date("l dS of F Y h:i:s A", filemtime($p_entry['filename'])) . ") than the extracted file (" . date("l dS of F Y h:i:s A", $p_entry['mtime']) . ")");
// ----- Change the file status
$p_entry['status'] = "newer_exist";
// ----- Return
//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
//return $v_result;
}
}
}
} else {
if (substr($p_entry['filename'], -1) == '/') {
$v_dir_to_check = $p_entry['filename'];
} else {
if (!strstr($p_entry['filename'], "/")) {
$v_dir_to_check = "";
//.........这里部分代码省略.........
示例6: privAddFile
function privAddFile($p_filename, &$p_header, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
{
$v_result = 1;
if ($p_filename == "") {
Zip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
return Zip::errorCode();
}
$v_stored_filename = $p_filename;
if ($p_remove_all_dir) {
$v_stored_filename = basename($p_filename);
} elseif ($p_remove_dir != "") {
if (substr($p_remove_dir, -1) != '/') {
$p_remove_dir .= "/";
}
if (substr($p_filename, 0, 2) == "./" || substr($p_remove_dir, 0, 2) == "./") {
if (substr($p_filename, 0, 2) == "./" && substr($p_remove_dir, 0, 2) != "./") {
$p_remove_dir = "./" . $p_remove_dir;
}
if (substr($p_filename, 0, 2) != "./" && substr($p_remove_dir, 0, 2) == "./") {
$p_remove_dir = substr($p_remove_dir, 2);
}
}
$v_compare = PclZipUtilPathInclusion($p_remove_dir, $p_filename);
if ($v_compare > 0) {
if ($v_compare == 2) {
$v_stored_filename = "";
} else {
$v_stored_filename = substr($p_filename, strlen($p_remove_dir));
}
}
}
if ($p_add_dir != "") {
if (substr($p_add_dir, -1) == "/") {
$v_stored_filename = $p_add_dir . $v_stored_filename;
} else {
$v_stored_filename = $p_add_dir . "/" . $v_stored_filename;
}
}
$v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
clearstatcache();
$p_header['version'] = 20;
$p_header['version_extracted'] = 10;
$p_header['flag'] = 0;
$p_header['compression'] = 0;
$p_header['mtime'] = filemtime($p_filename);
$p_header['crc'] = 0;
$p_header['compressed_size'] = 0;
$p_header['size'] = filesize($p_filename);
$p_header['filename_len'] = strlen($p_filename);
$p_header['extra_len'] = 0;
$p_header['comment_len'] = 0;
$p_header['disk'] = 0;
$p_header['internal'] = 0;
$p_header['external'] = is_file($p_filename) ? 0x0 : 0x10;
$p_header['offset'] = 0;
$p_header['filename'] = $p_filename;
$p_header['stored_filename'] = $v_stored_filename;
$p_header['extra'] = '';
$p_header['comment'] = '';
$p_header['status'] = 'ok';
$p_header['index'] = -1;
if ($p_header['stored_filename'] == "") {
$p_header['status'] = "filtered";
}
if (strlen($p_header['stored_filename']) > 0xff) {
$p_header['status'] = 'filename_too_long';
}
if ($p_header['status'] == 'ok') {
if (is_file($p_filename)) {
if (($v_file = @fopen($p_filename, "rb")) == 0) {
Zip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '{$p_filename}' in binary read mode");
return Zip::errorCode();
}
if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
$v_content_compressed = @fread($v_file, $p_header['size']);
$p_header['crc'] = @crc32($v_content_compressed);
$p_header['compressed_size'] = $p_header['size'];
$p_header['compression'] = 0;
} else {
$v_content = @fread($v_file, $p_header['size']);
$p_header['crc'] = @crc32($v_content);
$v_content_compressed = @gzdeflate($v_content);
$p_header['compressed_size'] = strlen($v_content_compressed);
$p_header['compression'] = 8;
}
if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
@fclose($v_file);
return $v_result;
}
@fwrite($this->zip_fd, $v_content_compressed, $p_header['compressed_size']);
@fclose($v_file);
} else {
if (@substr($p_header['stored_filename'], -1) != '/') {
$p_header['stored_filename'] .= '/';
}
$p_header['size'] = 0;
$p_header['external'] = 0x10;
if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
return $v_result;
}
//.........这里部分代码省略.........