📄 pcltar.lib.php
字号:
// relative to $p_path. // If a directory is sp锟絚ified in the list, all the files from this directory // will be extracted. // If a file with the same name already exists it will be replaced. // If the path to the file does not exist, it will be created. // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the // function will determine the type of the archive. // Parameters : // $p_tarname : Name of an existing tar file // $p_filelist : An array containing file or directory names, or // a string containing one filename or directory name, or // a string containing a list of filenames and/or directory // names separated by spaces. // $p_path : Path where the files will be extracted. The files will use // their memorized path from $p_path. // If $p_path is "", files will be extracted in "./". // $p_remove_path : Path to remove (from the file memorized path) while writing the // extracted files. If the path does not match the file path, // the file is extracted with its memorized path. // $p_path and $p_remove_path are commulative. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension // Return Values : // Same as PclTarList() // -------------------------------------------------------------------------------- function PclTarExtractList($p_tarname, $p_filelist, $p_path="./", $p_remove_path="", $p_mode="") { TrFctStart(__FILE__, __LINE__, "PclTarExtractList", "tar=$p_tarname, list, path=$p_path, remove_path='$p_remove_path', mode='$p_mode'"); $v_result=1; // ----- Extract the tar format from the extension if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz"))) { if (($p_mode = PclTarHandleExtension($p_tarname)) == "") { // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return 0; } } // ----- Look if the $p_filelist is really an array if (is_array($p_filelist)) { // ----- Call the extracting fct if (($v_result = PclTarHandleExtract($p_tarname, $p_filelist, $p_list, "partial", $p_path, $v_tar_mode, $p_remove_path)) != 1) { TrFctEnd(__FILE__, __LINE__, 0, PclErrorString()); return(0); } } // ----- Look if the $p_filelist is a string else if (is_string($p_filelist)) { // ----- Create a list with the elements from the string $v_list = explode(" ", $p_filelist); // ----- Call the extracting fct if (($v_result = PclTarHandleExtract($p_tarname, $v_list, $p_list, "partial", $p_path, $v_tar_mode, $p_remove_path)) != 1) { TrFctEnd(__FILE__, __LINE__, 0, PclErrorString()); return(0); } } // ----- Invalid variable else { // ----- Error log PclErrorLog(-3, "Invalid variable type p_filelist"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return 0; } // ----- Return TrFctEnd(__FILE__, __LINE__, $p_list); return $p_list; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclTarExtractIndex() // Description : // Extract the files present in the archive $p_tarname and specified at // the indexes in $p_index, in the directory // $p_path. The relative path of the archived files are keep and become // relative to $p_path. // If a directory is specified in the list, the directory only is created. All // the file stored in this archive for this directory // are not extracted. // If a file with the same name already exists it will be replaced. // If the path to the file does not exist, it will be created. // Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the // function will determine the type of the archive. // Parameters : // $p_tarname : Name of an existing tar file // $p_index : A single index (integer) or a string of indexes of files to // extract. The form of the string is "0,4-6,8-12" with only numbers // and '-' for range or ',' to separate ranges. No spaces or ';' // are allowed. // $p_path : Path where the files will be extracted. The files will use // their memorized path from $p_path. // If $p_path is "", files will be extracted in "./". // $p_remove_path : Path to remove (from the file memorized path) while writing the // extracted files. If the path does not match the file path, // the file is extracted with its memorized path. // $p_path and $p_remove_path are commulative. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension // Return Values : // Same as PclTarList() // -------------------------------------------------------------------------------- function PclTarExtractIndex($p_tarname, $p_index, $p_path="./", $p_remove_path="", $p_mode="") { TrFctStart(__FILE__, __LINE__, "PclTarExtractIndex", "tar=$p_tarname, index='$p_index', path=$p_path, remove_path='$p_remove_path', mode='$p_mode'"); $v_result=1; // ----- Extract the tar format from the extension if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz"))) { if (($p_mode = PclTarHandleExtension($p_tarname)) == "") { // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return 0; } } // ----- Look if the $p_index is really an integer if (is_integer($p_index)) { // ----- Call the extracting fct if (($v_result = PclTarHandleExtractByIndexList($p_tarname, "$p_index", $p_list, $p_path, $p_remove_path, $v_tar_mode)) != 1) { TrFctEnd(__FILE__, __LINE__, 0, PclErrorString()); return(0); } } // ----- Look if the $p_filelist is a string else if (is_string($p_index)) { // ----- Call the extracting fct if (($v_result = PclTarHandleExtractByIndexList($p_tarname, $p_index, $p_list, $p_path, $p_remove_path, $v_tar_mode)) != 1) { TrFctEnd(__FILE__, __LINE__, 0, PclErrorString()); return(0); } } // ----- Invalid variable else { // ----- Error log PclErrorLog(-3, "Invalid variable type $p_index"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return 0; } // ----- Return TrFctEnd(__FILE__, __LINE__, $p_list); return $p_list; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclTarDelete() // Description : // This function deletes from the archive $p_tarname the files which are listed // in $p_filelist. $p_filelist can be a string with file names separated by // spaces, or an array containing the file names. // Parameters : // $p_tarname : Name of an existing tar file // $p_filelist : An array or a string containing file names to remove from the // archive. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension // Return Values : // List of the files which are kept in the archive (same format as PclTarList()) // -------------------------------------------------------------------------------- function PclTarDelete($p_tarname, $p_filelist, $p_mode="") { TrFctStart(__FILE__, __LINE__, "PclTarDelete", "tar='$p_tarname', list='$p_filelist', mode='$p_mode'"); $v_result=1; // ----- Extract the tar format from the extension if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz"))) { if (($p_mode = PclTarHandleExtension($p_tarname)) == "") { // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return 0; } } // ----- Look if the $p_filelist is really an array if (is_array($p_filelist)) { // ----- Call the extracting fct if (($v_result = PclTarHandleDelete($p_tarname, $p_filelist, $p_list, $p_mode)) != 1) { TrFctEnd(__FILE__, __LINE__, 0, PclErrorString()); return(0); } } // ----- Look if the $p_filelist is a string else if (is_string($p_filelist)) { // ----- Create a list with the elements from the string $v_list = explode(" ", $p_filelist); // ----- Call the extracting fct if (($v_result = PclTarHandleDelete($p_tarname, $v_list, $p_list, $p_mode)) != 1) { TrFctEnd(__FILE__, __LINE__, 0, PclErrorString()); return(0); } } // ----- Invalid variable else { // ----- Error log PclErrorLog(-3, "Invalid variable type p_filelist"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return 0; } // ----- Return TrFctEnd(__FILE__, __LINE__, $p_list); return $p_list; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclTarUpdate() // Description : // This function updates the files in $p_filelist which are already in the // $p_tarname archive with an older last modified date. If the file does not // exist, it is added at the end of the archive. // Parameters : // $p_tarname : Name of an existing tar file // $p_filelist : An array or a string containing file names to update from the // archive. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension // Return Values : // List of the files contained in the archive. The field status contains // "updated", "not_updated", "added" or "ok" for the files not concerned. // -------------------------------------------------------------------------------- function PclTarUpdate($p_tarname, $p_filelist, $p_mode="", $p_add_dir="", $p_remove_dir="") { TrFctStart(__FILE__, __LINE__, "PclTarUpdate", "tar='$p_tarname', list='$p_filelist', mode='$p_mode'"); $v_result=1; // ----- Extract the tar format from the extension if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz"))) { if (($p_mode = PclTarHandleExtension($p_tarname)) == "") { // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return 0; } } // ----- Look if the $p_filelist is really an array if (is_array($p_filelist)) { // ----- Call the extracting fct if (($v_result = PclTarHandleUpdate($p_tarname, $p_filelist, $p_list, $p_mode, $p_add_dir, $p_remove_dir)) != 1) { TrFctEnd(__FILE__, __LINE__, 0, PclErrorString()); return(0); } } // ----- Look if the $p_filelist is a string else if (is_string($p_filelist)) { // ----- Create a list with the elements from the string $v_list = explode(" ", $p_filelist); // ----- Call the extracting fct if (($v_result = PclTarHandleUpdate($p_tarname, $v_list, $p_list, $p_mode, $p_add_dir, $p_remove_dir)) != 1) { TrFctEnd(__FILE__, __LINE__, 0, PclErrorString()); return(0); } } // ----- Invalid variable else { // ----- Error log PclErrorLog(-3, "Invalid variable type p_filelist"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return 0; } // ----- Return TrFctEnd(__FILE__, __LINE__, $p_list); return $p_list; } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // Function : PclTarMerge() // Description : // This function add the content of $p_tarname_add at the end of $p_tarname. // Parameters : // $p_tarname : Name of an existing tar file // $p_tarname_add : Name of an existing tar file taht will be added at the end // of $p_tarname. // $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension // $p_mode_add : 'tar' or 'tgz', if not set, will be determined by $p_tarname_add // extension // Return Values : // List of the files contained in the archive. The field status contains // "updated", "not_updated", "added" or "ok" for the files not concerned. // -------------------------------------------------------------------------------- function PclTarMerge($p_tarname, $p_tarname_add, $p_mode="", $p_mode_add="") { TrFctStart(__FILE__, __LINE__, "PclTarMerge", "tar='$p_tarname', tar_add='$p_tarname_add', mode='$p_mode', mode_add='$p_mode_add'"); $v_result=1; // ----- Check the parameters if (($p_tarname == "") || ($p_tarname_add == "")) { // ----- Error log PclErrorLog(-3, "Invalid empty archive name"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return PclErrorCode(); } // ----- Extract the tar format from the extension if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz"))) { if (($p_mode = PclTarHandleExtension($p_tarname)) == "") { // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return 0; } } if (($p_mode_add == "") || (($p_mode_add!="tar") && ($p_mode_add!="tgz"))) { if (($p_mode_add = PclTarHandleExtension($p_tarname_add)) == "") { // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return 0; } } // ----- Clear filecache clearstatcache(); // ----- Check the file size if ((!is_file($p_tarname)) || (((($v_size = filesize($p_tarname)) % 512) != 0) && ($p_mode=="tar"))) { // ----- Error log if (!is_file($p_tarname)) PclErrorLog(-4, "Archive '$p_tarname' does not exist"); else PclErrorLog(-6, "Archive '$p_tarname' has invalid size ".filesize($p_tarname)."(not a 512 block multiple)"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return PclErrorCode(); } if ((!is_file($p_tarname_add)) || (((($v_size_add = filesize($p_tarname_add)) % 512) != 0) && ($p_mode_add=="tar"))) { // ----- Error log if (!is_file($p_tarname_add)) PclErrorLog(-4, "Archive '$p_tarname_add' does not exist"); else PclErrorLog(-6, "Archive '$p_tarname_add' has invalid size ".filesize($p_tarname_add)."(not a 512 block multiple)"); // ----- Return TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString()); return PclErrorCode(); } // ----- Look for compressed archive if ($p_mode == "tgz") { // ----- Open the file in read mode
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -