PageRenderTime 65ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wp-all-import/libraries/pclzip.lib.php

https://gitlab.com/f3z0/tc-site
PHP | 5714 lines | 2967 code | 920 blank | 1827 comment | 963 complexity | 8598b80cc05d49f884c921ea9c4a4550 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, Apache-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // --------------------------------------------------------------------------------
  3. // PhpConcept Library - Zip Module 2.8.2
  4. // --------------------------------------------------------------------------------
  5. // License GNU/LGPL - Vincent Blavet - August 2009
  6. // http://www.phpconcept.net
  7. // --------------------------------------------------------------------------------
  8. //
  9. // Presentation :
  10. // PclZip is a PHP library that manage ZIP archives.
  11. // So far tests show that archives generated by PclZip are readable by
  12. // WinZip application and other tools.
  13. //
  14. // Description :
  15. // See readme.txt and http://www.phpconcept.net
  16. //
  17. // Warning :
  18. // This library and the associated files are non commercial, non professional
  19. // work.
  20. // It should not have unexpected results. However if any damage is caused by
  21. // this software the author can not be responsible.
  22. // The use of this software is at the risk of the user.
  23. //
  24. // --------------------------------------------------------------------------------
  25. // $Id: pclzip.lib.php,v 1.60 2009/09/30 21:01:04 vblavet Exp $
  26. // --------------------------------------------------------------------------------
  27. // ----- Constants
  28. if (!defined('PCLZIP_READ_BLOCK_SIZE')) {
  29. define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
  30. }
  31. // ----- File list separator
  32. // In version 1.x of PclZip, the separator for file list is a space
  33. // (which is not a very smart choice, specifically for windows paths !).
  34. // A better separator should be a comma (,). This constant gives you the
  35. // abilty to change that.
  36. // However notice that changing this value, may have impact on existing
  37. // scripts, using space separated filenames.
  38. // Recommanded values for compatibility with older versions :
  39. //define( 'PCLZIP_SEPARATOR', ' ' );
  40. // Recommanded values for smart separation of filenames.
  41. if (!defined('PCLZIP_SEPARATOR')) {
  42. define( 'PCLZIP_SEPARATOR', ',' );
  43. }
  44. // ----- Error configuration
  45. // 0 : PclZip Class integrated error handling
  46. // 1 : PclError external library error handling. By enabling this
  47. // you must ensure that you have included PclError library.
  48. // [2,...] : reserved for futur use
  49. if (!defined('PCLZIP_ERROR_EXTERNAL')) {
  50. define( 'PCLZIP_ERROR_EXTERNAL', 0 );
  51. }
  52. // ----- Optional static temporary directory
  53. // By default temporary files are generated in the script current
  54. // path.
  55. // If defined :
  56. // - MUST BE terminated by a '/'.
  57. // - MUST be a valid, already created directory
  58. // Samples :
  59. // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' );
  60. // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' );
  61. $wp_uploads = wp_upload_dir();
  62. if (!defined('PCLZIP_TEMPORARY_DIR')) {
  63. define( 'PCLZIP_TEMPORARY_DIR', $wp_uploads['path'] );
  64. }
  65. // ----- Optional threshold ratio for use of temporary files
  66. // Pclzip sense the size of the file to add/extract and decide to
  67. // use or not temporary file. The algorythm is looking for
  68. // memory_limit of PHP and apply a ratio.
  69. // threshold = memory_limit * ratio.
  70. // Recommended values are under 0.5. Default 0.47.
  71. // Samples :
  72. // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 );
  73. if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) {
  74. define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 );
  75. }
  76. // --------------------------------------------------------------------------------
  77. // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
  78. // --------------------------------------------------------------------------------
  79. // ----- Global variables
  80. $g_pclzip_version = "2.8.2";
  81. // ----- Error codes
  82. // -1 : Unable to open file in binary write mode
  83. // -2 : Unable to open file in binary read mode
  84. // -3 : Invalid parameters
  85. // -4 : File does not exist
  86. // -5 : Filename is too long (max. 255)
  87. // -6 : Not a valid zip file
  88. // -7 : Invalid extracted file size
  89. // -8 : Unable to create directory
  90. // -9 : Invalid archive extension
  91. // -10 : Invalid archive format
  92. // -11 : Unable to delete file (unlink)
  93. // -12 : Unable to rename file (rename)
  94. // -13 : Invalid header checksum
  95. // -14 : Invalid archive size
  96. define( 'PCLZIP_ERR_USER_ABORTED', 2 );
  97. define( 'PCLZIP_ERR_NO_ERROR', 0 );
  98. define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
  99. define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
  100. define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
  101. define( 'PCLZIP_ERR_MISSING_FILE', -4 );
  102. define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
  103. define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
  104. define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
  105. define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
  106. define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
  107. define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
  108. define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
  109. define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
  110. define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
  111. define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
  112. define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
  113. define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
  114. define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );
  115. define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );
  116. define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );
  117. define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 );
  118. define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 );
  119. // ----- Options values
  120. define( 'PCLZIP_OPT_PATH', 77001 );
  121. define( 'PCLZIP_OPT_ADD_PATH', 77002 );
  122. define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
  123. define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
  124. define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
  125. define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
  126. define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
  127. define( 'PCLZIP_OPT_BY_NAME', 77008 );
  128. define( 'PCLZIP_OPT_BY_INDEX', 77009 );
  129. define( 'PCLZIP_OPT_BY_EREG', 77010 );
  130. define( 'PCLZIP_OPT_BY_PREG', 77011 );
  131. define( 'PCLZIP_OPT_COMMENT', 77012 );
  132. define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
  133. define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
  134. define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
  135. define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );
  136. define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
  137. // Having big trouble with crypt. Need to multiply 2 long int
  138. // which is not correctly supported by PHP ...
  139. //define( 'PCLZIP_OPT_CRYPT', 77018 );
  140. define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );
  141. define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 );
  142. define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias
  143. define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 );
  144. define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias
  145. define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 );
  146. define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias
  147. // ----- File description attributes
  148. define( 'PCLZIP_ATT_FILE_NAME', 79001 );
  149. define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 );
  150. define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 );
  151. define( 'PCLZIP_ATT_FILE_MTIME', 79004 );
  152. define( 'PCLZIP_ATT_FILE_CONTENT', 79005 );
  153. define( 'PCLZIP_ATT_FILE_COMMENT', 79006 );
  154. // ----- Call backs values
  155. define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
  156. define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
  157. define( 'PCLZIP_CB_PRE_ADD', 78003 );
  158. define( 'PCLZIP_CB_POST_ADD', 78004 );
  159. /* For futur use
  160. define( 'PCLZIP_CB_PRE_LIST', 78005 );
  161. define( 'PCLZIP_CB_POST_LIST', 78006 );
  162. define( 'PCLZIP_CB_PRE_DELETE', 78007 );
  163. define( 'PCLZIP_CB_POST_DELETE', 78008 );
  164. */
  165. // --------------------------------------------------------------------------------
  166. // Class : PclZip
  167. // Description :
  168. // PclZip is the class that represent a Zip archive.
  169. // The public methods allow the manipulation of the archive.
  170. // Attributes :
  171. // Attributes must not be accessed directly.
  172. // Methods :
  173. // PclZip() : Object creator
  174. // create() : Creates the Zip archive
  175. // listContent() : List the content of the Zip archive
  176. // extract() : Extract the content of the archive
  177. // properties() : List the properties of the archive
  178. // --------------------------------------------------------------------------------
  179. if (!class_exists('PclZip')):
  180. class PclZip
  181. {
  182. // ----- Filename of the zip file
  183. var $zipname = '';
  184. // ----- File descriptor of the zip file
  185. var $zip_fd = 0;
  186. // ----- Internal error handling
  187. var $error_code = 1;
  188. var $error_string = '';
  189. // ----- Current status of the magic_quotes_runtime
  190. // This value store the php configuration for magic_quotes
  191. // The class can then disable the magic_quotes and reset it after
  192. var $magic_quotes_status;
  193. // --------------------------------------------------------------------------------
  194. // Function : PclZip()
  195. // Description :
  196. // Creates a PclZip object and set the name of the associated Zip archive
  197. // filename.
  198. // Note that no real action is taken, if the archive does not exist it is not
  199. // created. Use create() for that.
  200. // --------------------------------------------------------------------------------
  201. function PclZip($p_zipname)
  202. {
  203. // ----- Tests the zlib
  204. if (!function_exists('gzopen'))
  205. {
  206. die('Abort '.basename(__FILE__).' : Missing zlib extensions');
  207. }
  208. // ----- Set the attributes
  209. $this->zipname = $p_zipname;
  210. $this->zip_fd = 0;
  211. $this->magic_quotes_status = -1;
  212. // ----- Return
  213. return;
  214. }
  215. // --------------------------------------------------------------------------------
  216. // --------------------------------------------------------------------------------
  217. // Function :
  218. // create($p_filelist, $p_add_dir="", $p_remove_dir="")
  219. // create($p_filelist, $p_option, $p_option_value, ...)
  220. // Description :
  221. // This method supports two different synopsis. The first one is historical.
  222. // This method creates a Zip Archive. The Zip file is created in the
  223. // filesystem. The files and directories indicated in $p_filelist
  224. // are added in the archive. See the parameters description for the
  225. // supported format of $p_filelist.
  226. // When a directory is in the list, the directory and its content is added
  227. // in the archive.
  228. // In this synopsis, the function takes an optional variable list of
  229. // options. See bellow the supported options.
  230. // Parameters :
  231. // $p_filelist : An array containing file or directory names, or
  232. // a string containing one filename or one directory name, or
  233. // a string containing a list of filenames and/or directory
  234. // names separated by spaces.
  235. // $p_add_dir : A path to add before the real path of the archived file,
  236. // in order to have it memorized in the archive.
  237. // $p_remove_dir : A path to remove from the real path of the file to archive,
  238. // in order to have a shorter path memorized in the archive.
  239. // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
  240. // is removed first, before $p_add_dir is added.
  241. // Options :
  242. // PCLZIP_OPT_ADD_PATH :
  243. // PCLZIP_OPT_REMOVE_PATH :
  244. // PCLZIP_OPT_REMOVE_ALL_PATH :
  245. // PCLZIP_OPT_COMMENT :
  246. // PCLZIP_CB_PRE_ADD :
  247. // PCLZIP_CB_POST_ADD :
  248. // Return Values :
  249. // 0 on failure,
  250. // The list of the added files, with a status of the add action.
  251. // (see PclZip::listContent() for list entry format)
  252. // --------------------------------------------------------------------------------
  253. function create($p_filelist)
  254. {
  255. $v_result=1;
  256. // ----- Reset the error handler
  257. $this->privErrorReset();
  258. // ----- Set default values
  259. $v_options = array();
  260. $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
  261. // ----- Look for variable options arguments
  262. $v_size = func_num_args();
  263. // ----- Look for arguments
  264. if ($v_size > 1) {
  265. // ----- Get the arguments
  266. $v_arg_list = func_get_args();
  267. // ----- Remove from the options list the first argument
  268. array_shift($v_arg_list);
  269. $v_size--;
  270. // ----- Look for first arg
  271. if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  272. // ----- Parse the options
  273. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  274. array (PCLZIP_OPT_REMOVE_PATH => 'optional',
  275. PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  276. PCLZIP_OPT_ADD_PATH => 'optional',
  277. PCLZIP_CB_PRE_ADD => 'optional',
  278. PCLZIP_CB_POST_ADD => 'optional',
  279. PCLZIP_OPT_NO_COMPRESSION => 'optional',
  280. PCLZIP_OPT_COMMENT => 'optional',
  281. PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
  282. PCLZIP_OPT_TEMP_FILE_ON => 'optional',
  283. PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
  284. //, PCLZIP_OPT_CRYPT => 'optional'
  285. ));
  286. if ($v_result != 1) {
  287. return 0;
  288. }
  289. }
  290. // ----- Look for 2 args
  291. // Here we need to support the first historic synopsis of the
  292. // method.
  293. else {
  294. // ----- Get the first argument
  295. $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
  296. // ----- Look for the optional second argument
  297. if ($v_size == 2) {
  298. $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
  299. }
  300. else if ($v_size > 2) {
  301. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
  302. "Invalid number / type of arguments");
  303. return 0;
  304. }
  305. }
  306. }
  307. // ----- Look for default option values
  308. $this->privOptionDefaultThreshold($v_options);
  309. // ----- Init
  310. $v_string_list = array();
  311. $v_att_list = array();
  312. $v_filedescr_list = array();
  313. $p_result_list = array();
  314. // ----- Look if the $p_filelist is really an array
  315. if (is_array($p_filelist)) {
  316. // ----- Look if the first element is also an array
  317. // This will mean that this is a file description entry
  318. if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
  319. $v_att_list = $p_filelist;
  320. }
  321. // ----- The list is a list of string names
  322. else {
  323. $v_string_list = $p_filelist;
  324. }
  325. }
  326. // ----- Look if the $p_filelist is a string
  327. else if (is_string($p_filelist)) {
  328. // ----- Create a list from the string
  329. $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
  330. }
  331. // ----- Invalid variable type for $p_filelist
  332. else {
  333. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
  334. return 0;
  335. }
  336. // ----- Reformat the string list
  337. if (sizeof($v_string_list) != 0) {
  338. foreach ($v_string_list as $v_string) {
  339. if ($v_string != '') {
  340. $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
  341. }
  342. else {
  343. }
  344. }
  345. }
  346. // ----- For each file in the list check the attributes
  347. $v_supported_attributes
  348. = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
  349. ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
  350. ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
  351. ,PCLZIP_ATT_FILE_MTIME => 'optional'
  352. ,PCLZIP_ATT_FILE_CONTENT => 'optional'
  353. ,PCLZIP_ATT_FILE_COMMENT => 'optional'
  354. );
  355. foreach ($v_att_list as $v_entry) {
  356. $v_result = $this->privFileDescrParseAtt($v_entry,
  357. $v_filedescr_list[],
  358. $v_options,
  359. $v_supported_attributes);
  360. if ($v_result != 1) {
  361. return 0;
  362. }
  363. }
  364. // ----- Expand the filelist (expand directories)
  365. $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
  366. if ($v_result != 1) {
  367. return 0;
  368. }
  369. // ----- Call the create fct
  370. $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
  371. if ($v_result != 1) {
  372. return 0;
  373. }
  374. // ----- Return
  375. return $p_result_list;
  376. }
  377. // --------------------------------------------------------------------------------
  378. // --------------------------------------------------------------------------------
  379. // Function :
  380. // add($p_filelist, $p_add_dir="", $p_remove_dir="")
  381. // add($p_filelist, $p_option, $p_option_value, ...)
  382. // Description :
  383. // This method supports two synopsis. The first one is historical.
  384. // This methods add the list of files in an existing archive.
  385. // If a file with the same name already exists, it is added at the end of the
  386. // archive, the first one is still present.
  387. // If the archive does not exist, it is created.
  388. // Parameters :
  389. // $p_filelist : An array containing file or directory names, or
  390. // a string containing one filename or one directory name, or
  391. // a string containing a list of filenames and/or directory
  392. // names separated by spaces.
  393. // $p_add_dir : A path to add before the real path of the archived file,
  394. // in order to have it memorized in the archive.
  395. // $p_remove_dir : A path to remove from the real path of the file to archive,
  396. // in order to have a shorter path memorized in the archive.
  397. // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
  398. // is removed first, before $p_add_dir is added.
  399. // Options :
  400. // PCLZIP_OPT_ADD_PATH :
  401. // PCLZIP_OPT_REMOVE_PATH :
  402. // PCLZIP_OPT_REMOVE_ALL_PATH :
  403. // PCLZIP_OPT_COMMENT :
  404. // PCLZIP_OPT_ADD_COMMENT :
  405. // PCLZIP_OPT_PREPEND_COMMENT :
  406. // PCLZIP_CB_PRE_ADD :
  407. // PCLZIP_CB_POST_ADD :
  408. // Return Values :
  409. // 0 on failure,
  410. // The list of the added files, with a status of the add action.
  411. // (see PclZip::listContent() for list entry format)
  412. // --------------------------------------------------------------------------------
  413. function add($p_filelist)
  414. {
  415. $v_result=1;
  416. // ----- Reset the error handler
  417. $this->privErrorReset();
  418. // ----- Set default values
  419. $v_options = array();
  420. $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
  421. // ----- Look for variable options arguments
  422. $v_size = func_num_args();
  423. // ----- Look for arguments
  424. if ($v_size > 1) {
  425. // ----- Get the arguments
  426. $v_arg_list = func_get_args();
  427. // ----- Remove form the options list the first argument
  428. array_shift($v_arg_list);
  429. $v_size--;
  430. // ----- Look for first arg
  431. if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  432. // ----- Parse the options
  433. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  434. array (PCLZIP_OPT_REMOVE_PATH => 'optional',
  435. PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  436. PCLZIP_OPT_ADD_PATH => 'optional',
  437. PCLZIP_CB_PRE_ADD => 'optional',
  438. PCLZIP_CB_POST_ADD => 'optional',
  439. PCLZIP_OPT_NO_COMPRESSION => 'optional',
  440. PCLZIP_OPT_COMMENT => 'optional',
  441. PCLZIP_OPT_ADD_COMMENT => 'optional',
  442. PCLZIP_OPT_PREPEND_COMMENT => 'optional',
  443. PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
  444. PCLZIP_OPT_TEMP_FILE_ON => 'optional',
  445. PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
  446. //, PCLZIP_OPT_CRYPT => 'optional'
  447. ));
  448. if ($v_result != 1) {
  449. return 0;
  450. }
  451. }
  452. // ----- Look for 2 args
  453. // Here we need to support the first historic synopsis of the
  454. // method.
  455. else {
  456. // ----- Get the first argument
  457. $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
  458. // ----- Look for the optional second argument
  459. if ($v_size == 2) {
  460. $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
  461. }
  462. else if ($v_size > 2) {
  463. // ----- Error log
  464. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
  465. // ----- Return
  466. return 0;
  467. }
  468. }
  469. }
  470. // ----- Look for default option values
  471. $this->privOptionDefaultThreshold($v_options);
  472. // ----- Init
  473. $v_string_list = array();
  474. $v_att_list = array();
  475. $v_filedescr_list = array();
  476. $p_result_list = array();
  477. // ----- Look if the $p_filelist is really an array
  478. if (is_array($p_filelist)) {
  479. // ----- Look if the first element is also an array
  480. // This will mean that this is a file description entry
  481. if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
  482. $v_att_list = $p_filelist;
  483. }
  484. // ----- The list is a list of string names
  485. else {
  486. $v_string_list = $p_filelist;
  487. }
  488. }
  489. // ----- Look if the $p_filelist is a string
  490. else if (is_string($p_filelist)) {
  491. // ----- Create a list from the string
  492. $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
  493. }
  494. // ----- Invalid variable type for $p_filelist
  495. else {
  496. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
  497. return 0;
  498. }
  499. // ----- Reformat the string list
  500. if (sizeof($v_string_list) != 0) {
  501. foreach ($v_string_list as $v_string) {
  502. $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
  503. }
  504. }
  505. // ----- For each file in the list check the attributes
  506. $v_supported_attributes
  507. = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
  508. ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
  509. ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
  510. ,PCLZIP_ATT_FILE_MTIME => 'optional'
  511. ,PCLZIP_ATT_FILE_CONTENT => 'optional'
  512. ,PCLZIP_ATT_FILE_COMMENT => 'optional'
  513. );
  514. foreach ($v_att_list as $v_entry) {
  515. $v_result = $this->privFileDescrParseAtt($v_entry,
  516. $v_filedescr_list[],
  517. $v_options,
  518. $v_supported_attributes);
  519. if ($v_result != 1) {
  520. return 0;
  521. }
  522. }
  523. // ----- Expand the filelist (expand directories)
  524. $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
  525. if ($v_result != 1) {
  526. return 0;
  527. }
  528. // ----- Call the create fct
  529. $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
  530. if ($v_result != 1) {
  531. return 0;
  532. }
  533. // ----- Return
  534. return $p_result_list;
  535. }
  536. // --------------------------------------------------------------------------------
  537. // --------------------------------------------------------------------------------
  538. // Function : listContent()
  539. // Description :
  540. // This public method, gives the list of the files and directories, with their
  541. // properties.
  542. // The properties of each entries in the list are (used also in other functions) :
  543. // filename : Name of the file. For a create or add action it is the filename
  544. // given by the user. For an extract function it is the filename
  545. // of the extracted file.
  546. // stored_filename : Name of the file / directory stored in the archive.
  547. // size : Size of the stored file.
  548. // compressed_size : Size of the file's data compressed in the archive
  549. // (without the headers overhead)
  550. // mtime : Last known modification date of the file (UNIX timestamp)
  551. // comment : Comment associated with the file
  552. // folder : true | false
  553. // index : index of the file in the archive
  554. // status : status of the action (depending of the action) :
  555. // Values are :
  556. // ok : OK !
  557. // filtered : the file / dir is not extracted (filtered by user)
  558. // already_a_directory : the file can not be extracted because a
  559. // directory with the same name already exists
  560. // write_protected : the file can not be extracted because a file
  561. // with the same name already exists and is
  562. // write protected
  563. // newer_exist : the file was not extracted because a newer file exists
  564. // path_creation_fail : the file is not extracted because the folder
  565. // does not exist and can not be created
  566. // write_error : the file was not extracted because there was a
  567. // error while writing the file
  568. // read_error : the file was not extracted because there was a error
  569. // while reading the file
  570. // invalid_header : the file was not extracted because of an archive
  571. // format error (bad file header)
  572. // Note that each time a method can continue operating when there
  573. // is an action error on a file, the error is only logged in the file status.
  574. // Return Values :
  575. // 0 on an unrecoverable failure,
  576. // The list of the files in the archive.
  577. // --------------------------------------------------------------------------------
  578. function listContent()
  579. {
  580. $v_result=1;
  581. // ----- Reset the error handler
  582. $this->privErrorReset();
  583. // ----- Check archive
  584. if (!$this->privCheckFormat()) {
  585. return(0);
  586. }
  587. // ----- Call the extracting fct
  588. $p_list = array();
  589. if (($v_result = $this->privList($p_list)) != 1)
  590. {
  591. unset($p_list);
  592. return(0);
  593. }
  594. // ----- Return
  595. return $p_list;
  596. }
  597. // --------------------------------------------------------------------------------
  598. // --------------------------------------------------------------------------------
  599. // Function :
  600. // extract($p_path="./", $p_remove_path="")
  601. // extract([$p_option, $p_option_value, ...])
  602. // Description :
  603. // This method supports two synopsis. The first one is historical.
  604. // This method extract all the files / directories from the archive to the
  605. // folder indicated in $p_path.
  606. // If you want to ignore the 'root' part of path of the memorized files
  607. // you can indicate this in the optional $p_remove_path parameter.
  608. // By default, if a newer file with the same name already exists, the
  609. // file is not extracted.
  610. //
  611. // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
  612. // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
  613. // at the end of the path value of PCLZIP_OPT_PATH.
  614. // Parameters :
  615. // $p_path : Path where the files and directories are to be extracted
  616. // $p_remove_path : First part ('root' part) of the memorized path
  617. // (if any similar) to remove while extracting.
  618. // Options :
  619. // PCLZIP_OPT_PATH :
  620. // PCLZIP_OPT_ADD_PATH :
  621. // PCLZIP_OPT_REMOVE_PATH :
  622. // PCLZIP_OPT_REMOVE_ALL_PATH :
  623. // PCLZIP_CB_PRE_EXTRACT :
  624. // PCLZIP_CB_POST_EXTRACT :
  625. // Return Values :
  626. // 0 or a negative value on failure,
  627. // The list of the extracted files, with a status of the action.
  628. // (see PclZip::listContent() for list entry format)
  629. // --------------------------------------------------------------------------------
  630. function extract()
  631. {
  632. $v_result=1;
  633. // ----- Reset the error handler
  634. $this->privErrorReset();
  635. // ----- Check archive
  636. if (!$this->privCheckFormat()) {
  637. return(0);
  638. }
  639. // ----- Set default values
  640. $v_options = array();
  641. // $v_path = "./";
  642. $v_path = '';
  643. $v_remove_path = "";
  644. $v_remove_all_path = false;
  645. // ----- Look for variable options arguments
  646. $v_size = func_num_args();
  647. // ----- Default values for option
  648. $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
  649. // ----- Look for arguments
  650. if ($v_size > 0) {
  651. // ----- Get the arguments
  652. $v_arg_list = func_get_args();
  653. // ----- Look for first arg
  654. if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  655. // ----- Parse the options
  656. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  657. array (PCLZIP_OPT_PATH => 'optional',
  658. PCLZIP_OPT_REMOVE_PATH => 'optional',
  659. PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  660. PCLZIP_OPT_ADD_PATH => 'optional',
  661. PCLZIP_CB_PRE_EXTRACT => 'optional',
  662. PCLZIP_CB_POST_EXTRACT => 'optional',
  663. PCLZIP_OPT_SET_CHMOD => 'optional',
  664. PCLZIP_OPT_BY_NAME => 'optional',
  665. PCLZIP_OPT_BY_EREG => 'optional',
  666. PCLZIP_OPT_BY_PREG => 'optional',
  667. PCLZIP_OPT_BY_INDEX => 'optional',
  668. PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
  669. PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
  670. PCLZIP_OPT_REPLACE_NEWER => 'optional'
  671. ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
  672. ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
  673. PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
  674. PCLZIP_OPT_TEMP_FILE_ON => 'optional',
  675. PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
  676. ));
  677. if ($v_result != 1) {
  678. return 0;
  679. }
  680. // ----- Set the arguments
  681. if (isset($v_options[PCLZIP_OPT_PATH])) {
  682. $v_path = $v_options[PCLZIP_OPT_PATH];
  683. }
  684. if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
  685. $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
  686. }
  687. if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  688. $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  689. }
  690. if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
  691. // ----- Check for '/' in last path char
  692. if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
  693. $v_path .= '/';
  694. }
  695. $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
  696. }
  697. }
  698. // ----- Look for 2 args
  699. // Here we need to support the first historic synopsis of the
  700. // method.
  701. else {
  702. // ----- Get the first argument
  703. $v_path = $v_arg_list[0];
  704. // ----- Look for the optional second argument
  705. if ($v_size == 2) {
  706. $v_remove_path = $v_arg_list[1];
  707. }
  708. else if ($v_size > 2) {
  709. // ----- Error log
  710. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
  711. // ----- Return
  712. return 0;
  713. }
  714. }
  715. }
  716. // ----- Look for default option values
  717. $this->privOptionDefaultThreshold($v_options);
  718. // ----- Trace
  719. // ----- Call the extracting fct
  720. $p_list = array();
  721. $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
  722. $v_remove_all_path, $v_options);
  723. if ($v_result < 1) {
  724. unset($p_list);
  725. return(0);
  726. }
  727. // ----- Return
  728. return $p_list;
  729. }
  730. // --------------------------------------------------------------------------------
  731. // --------------------------------------------------------------------------------
  732. // Function :
  733. // extractByIndex($p_index, $p_path="./", $p_remove_path="")
  734. // extractByIndex($p_index, [$p_option, $p_option_value, ...])
  735. // Description :
  736. // This method supports two synopsis. The first one is historical.
  737. // This method is doing a partial extract of the archive.
  738. // The extracted files or folders are identified by their index in the
  739. // archive (from 0 to n).
  740. // Note that if the index identify a folder, only the folder entry is
  741. // extracted, not all the files included in the archive.
  742. // Parameters :
  743. // $p_index : A single index (integer) or a string of indexes of files to
  744. // extract. The form of the string is "0,4-6,8-12" with only numbers
  745. // and '-' for range or ',' to separate ranges. No spaces or ';'
  746. // are allowed.
  747. // $p_path : Path where the files and directories are to be extracted
  748. // $p_remove_path : First part ('root' part) of the memorized path
  749. // (if any similar) to remove while extracting.
  750. // Options :
  751. // PCLZIP_OPT_PATH :
  752. // PCLZIP_OPT_ADD_PATH :
  753. // PCLZIP_OPT_REMOVE_PATH :
  754. // PCLZIP_OPT_REMOVE_ALL_PATH :
  755. // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
  756. // not as files.
  757. // The resulting content is in a new field 'content' in the file
  758. // structure.
  759. // This option must be used alone (any other options are ignored).
  760. // PCLZIP_CB_PRE_EXTRACT :
  761. // PCLZIP_CB_POST_EXTRACT :
  762. // Return Values :
  763. // 0 on failure,
  764. // The list of the extracted files, with a status of the action.
  765. // (see PclZip::listContent() for list entry format)
  766. // --------------------------------------------------------------------------------
  767. //function extractByIndex($p_index, options...)
  768. function extractByIndex($p_index)
  769. {
  770. $v_result=1;
  771. // ----- Reset the error handler
  772. $this->privErrorReset();
  773. // ----- Check archive
  774. if (!$this->privCheckFormat()) {
  775. return(0);
  776. }
  777. // ----- Set default values
  778. $v_options = array();
  779. // $v_path = "./";
  780. $v_path = '';
  781. $v_remove_path = "";
  782. $v_remove_all_path = false;
  783. // ----- Look for variable options arguments
  784. $v_size = func_num_args();
  785. // ----- Default values for option
  786. $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
  787. // ----- Look for arguments
  788. if ($v_size > 1) {
  789. // ----- Get the arguments
  790. $v_arg_list = func_get_args();
  791. // ----- Remove form the options list the first argument
  792. array_shift($v_arg_list);
  793. $v_size--;
  794. // ----- Look for first arg
  795. if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  796. // ----- Parse the options
  797. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  798. array (PCLZIP_OPT_PATH => 'optional',
  799. PCLZIP_OPT_REMOVE_PATH => 'optional',
  800. PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  801. PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
  802. PCLZIP_OPT_ADD_PATH => 'optional',
  803. PCLZIP_CB_PRE_EXTRACT => 'optional',
  804. PCLZIP_CB_POST_EXTRACT => 'optional',
  805. PCLZIP_OPT_SET_CHMOD => 'optional',
  806. PCLZIP_OPT_REPLACE_NEWER => 'optional'
  807. ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
  808. ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
  809. PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
  810. PCLZIP_OPT_TEMP_FILE_ON => 'optional',
  811. PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
  812. ));
  813. if ($v_result != 1) {
  814. return 0;
  815. }
  816. // ----- Set the arguments
  817. if (isset($v_options[PCLZIP_OPT_PATH])) {
  818. $v_path = $v_options[PCLZIP_OPT_PATH];
  819. }
  820. if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
  821. $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
  822. }
  823. if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  824. $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  825. }
  826. if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
  827. // ----- Check for '/' in last path char
  828. if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
  829. $v_path .= '/';
  830. }
  831. $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
  832. }
  833. if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
  834. $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
  835. }
  836. else {
  837. }
  838. }
  839. // ----- Look for 2 args
  840. // Here we need to support the first historic synopsis of the
  841. // method.
  842. else {
  843. // ----- Get the first argument
  844. $v_path = $v_arg_list[0];
  845. // ----- Look for the optional second argument
  846. if ($v_size == 2) {
  847. $v_remove_path = $v_arg_list[1];
  848. }
  849. else if ($v_size > 2) {
  850. // ----- Error log
  851. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
  852. // ----- Return
  853. return 0;
  854. }
  855. }
  856. }
  857. // ----- Trace
  858. // ----- Trick
  859. // Here I want to reuse extractByRule(), so I need to parse the $p_index
  860. // with privParseOptions()
  861. $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
  862. $v_options_trick = array();
  863. $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
  864. array (PCLZIP_OPT_BY_INDEX => 'optional' ));
  865. if ($v_result != 1) {
  866. return 0;
  867. }
  868. $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
  869. // ----- Look for default option values
  870. $this->privOptionDefaultThreshold($v_options);
  871. // ----- Call the extracting fct
  872. if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
  873. return(0);
  874. }
  875. // ----- Return
  876. return $p_list;
  877. }
  878. // --------------------------------------------------------------------------------
  879. // --------------------------------------------------------------------------------
  880. // Function :
  881. // delete([$p_option, $p_option_value, ...])
  882. // Description :
  883. // This method removes files from the archive.
  884. // If no parameters are given, then all the archive is emptied.
  885. // Parameters :
  886. // None or optional arguments.
  887. // Options :
  888. // PCLZIP_OPT_BY_INDEX :
  889. // PCLZIP_OPT_BY_NAME :
  890. // PCLZIP_OPT_BY_EREG :
  891. // PCLZIP_OPT_BY_PREG :
  892. // Return Values :
  893. // 0 on failure,
  894. // The list of the files which are still present in the archive.
  895. // (see PclZip::listContent() for list entry format)
  896. // --------------------------------------------------------------------------------
  897. function delete()
  898. {
  899. $v_result=1;
  900. // ----- Reset the error handler
  901. $this->privErrorReset();
  902. // ----- Check archive
  903. if (!$this->privCheckFormat()) {
  904. return(0);
  905. }
  906. // ----- Set default values
  907. $v_options = array();
  908. // ----- Look for variable options arguments
  909. $v_size = func_num_args();
  910. // ----- Look for arguments
  911. if ($v_size > 0) {
  912. // ----- Get the arguments
  913. $v_arg_list = func_get_args();
  914. // ----- Parse the options
  915. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  916. array (PCLZIP_OPT_BY_NAME => 'optional',
  917. PCLZIP_OPT_BY_EREG => 'optional',
  918. PCLZIP_OPT_BY_PREG => 'optional',
  919. PCLZIP_OPT_BY_INDEX => 'optional' ));
  920. if ($v_result != 1) {
  921. return 0;
  922. }
  923. }
  924. // ----- Magic quotes trick
  925. $this->privDisableMagicQuotes();
  926. // ----- Call the delete fct
  927. $v_list = array();
  928. if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
  929. $this->privSwapBackMagicQuotes();
  930. unset($v_list);
  931. return(0);
  932. }
  933. // ----- Magic quotes trick
  934. $this->privSwapBackMagicQuotes();
  935. // ----- Return
  936. return $v_list;
  937. }
  938. // --------------------------------------------------------------------------------
  939. // --------------------------------------------------------------------------------
  940. // Function : deleteByIndex()
  941. // Description :
  942. // ***** Deprecated *****
  943. // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
  944. // --------------------------------------------------------------------------------
  945. function deleteByIndex($p_index)
  946. {
  947. $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
  948. // ----- Return
  949. return $p_list;
  950. }
  951. // --------------------------------------------------------------------------------
  952. // --------------------------------------------------------------------------------
  953. // Function : properties()
  954. // Description :
  955. // This method gives the properties of the archive.
  956. // The properties are :
  957. // nb : Number of files in the archive
  958. // comment : Comment associated with the archive file
  959. // status : not_exist, ok
  960. // Parameters :
  961. // None
  962. // Return Values :
  963. // 0 on failure,
  964. // An array with the archive properties.
  965. // --------------------------------------------------------------------------------
  966. function properties()
  967. {
  968. // ----- Reset the error handler
  969. $this->privErrorReset();
  970. // ----- Magic quotes trick
  971. $this->privDisableMagicQuotes();
  972. // ----- Check archive
  973. if (!$this->privCheckFormat()) {
  974. $this->privSwapBackMagicQuotes();
  975. return(0);
  976. }
  977. // ----- Default properties
  978. $v_prop = array();
  979. $v_prop['comment'] = '';
  980. $v_prop['nb'] = 0;
  981. $v_prop['status'] = 'not_exist';
  982. // ----- Look if file exists
  983. if (@is_file($this->zipname))
  984. {
  985. // ----- Open the zip file
  986. if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
  987. {
  988. $this->privSwapBackMagicQuotes();
  989. // ----- Error log
  990. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
  991. // ----- Return
  992. return 0;
  993. }
  994. // ----- Read the central directory informations
  995. $v_central_dir = array();
  996. if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  997. {
  998. $this->privSwapBackMagicQuotes();
  999. return 0;
  1000. }
  1001. // ----- Close the zip file
  1002. $this->privCloseFd();
  1003. // ----- Set the user attributes
  1004. $v_prop['comment'] = $v_central_dir['comment'];
  1005. $v_prop['nb'] = $v_central_dir['entries'];
  1006. $v_prop['status'] = 'ok';
  1007. }
  1008. // ----- Magic quotes trick
  1009. $this->privSwapBackMagicQuotes();
  1010. // ----- Return
  1011. return $v_prop;
  1012. }
  1013. // --------------------------------------------------------------------------------
  1014. // --------------------------------------------------------------------------------
  1015. // Function : duplicate()
  1016. // Description :
  1017. // This method creates an archive by copying the content of an other one. If
  1018. // the archive already exist, it is replaced by the new one without any warning.
  1019. // Parameters :
  1020. // $p_archive : The filename of a valid archive, or
  1021. // a valid PclZip object.
  1022. // Return Values :
  1023. // 1 on success.
  1024. // 0 or a negative value on error (error code).
  1025. // --------------------------------------------------------------------------------
  1026. function duplicate($p_archive)
  1027. {
  1028. $v_result = 1;
  1029. // ----- Reset the error handler
  1030. $this->privErrorReset();
  1031. // ----- Look if the $p_archive is a PclZip object
  1032. if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
  1033. {
  1034. // ----- Duplicate the archive
  1035. $v_result = $this->privDuplicate($p_archive->zipname);
  1036. }
  1037. // ----- Look if the $p_archive is a string (so a filename)
  1038. else if (is_string($p_archive))
  1039. {
  1040. // ----- Check that $p_archive is a valid zip file
  1041. // TBC : Should also check the archive format
  1042. if (!is_file($p_archive)) {
  1043. // ----- Error log
  1044. PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
  1045. $v_result = PCLZIP_ERR_MISSING_FILE;
  1046. }
  1047. else {
  1048. // ----- Duplicate the archive
  1049. $v_result = $this->privDuplicate($p_archive);
  1050. }
  1051. }
  1052. // ----- Invalid variable
  1053. else
  1054. {
  1055. // ----- Error log
  1056. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
  1057. $v_result = PCLZIP_ERR_INVALID_PARAMETER;
  1058. }
  1059. // ----- Return
  1060. return $v_result;
  1061. }
  1062. // --------------------------------------------------------------------------------
  1063. // --------------------------------------------------------------------------------
  1064. // Function : merge()
  1065. // Description :
  1066. // This method merge the $p_archive_to_add archive at the end of the current
  1067. // one ($this).
  1068. // If the archive ($this) does not exist, the merge becomes a duplicate.
  1069. // If the $p_archive_to_add archive does not exist, the merge is a success.
  1070. // Parameters :
  1071. // $p_archive_to_add : It can be directly the filename of a valid zip archive,
  1072. // or a PclZip object archive.
  1073. // Return Values :
  1074. // 1 on success,
  1075. // 0 or negative values on error (see below).
  1076. // --------------------------------------------------------------------------------
  1077. function merge($p_archive_to_add)
  1078. {
  1079. $v_result = 1;
  1080. // ----- Reset the error handler
  1081. $this->privErrorReset();
  1082. // ----- Check archive
  1083. if (!$this->privCheckFormat()) {
  1084. return(0);
  1085. }
  1086. // ----- Look if the $p_archive_to_add is a PclZip object
  1087. if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
  1088. {
  1089. // ----- Merge the archive
  1090. $v_result = $this->privMerge($p_archive_to_add);
  1091. }
  1092. // ----- Look if the $p_archive_to_add is a string (so a filename)
  1093. else if (is_string($p_archive_to_add))
  1094. {
  1095. // ----- Create a temporary archive
  1096. $v_object_archive = new PclZip($p_archive_to_add);
  1097. // ----- Merge the archive
  1098. $v_result = $this->privMerge($v_object_archive);
  1099. }
  1100. // ----- Invalid variable
  1101. else
  1102. {
  1103. // ----- Error log
  1104. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
  1105. $v_result = PCLZIP_ERR_INVALID_PARAMETER;
  1106. }
  1107. // ----- Return
  1108. return $v_result;
  1109. }
  1110. // --------------------------------------------------------------------------------
  1111. // --------------------------------------------------------------------------------
  1112. // Function : errorCode()
  1113. // Description :
  1114. // Parameters :
  1115. // --------------------------------------------------------------------------------
  1116. function errorCode()
  1117. {
  1118. if (PCLZIP_ERROR_EXTERNAL == 1) {
  1119. return(PclErrorCode());
  1120. }
  1121. else {
  1122. return($this->error_code);
  1123. }
  1124. }
  1125. // --------------------------------------------------------------------------------
  1126. // --------------------------------------------------------------------------------
  1127. // Function : errorName()
  1128. // Description :
  1129. // Parameters :
  1130. // --------------------------------------------------------------------------------
  1131. function errorName($p_with_code=false)
  1132. {
  1133. $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
  1134. PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
  1135. PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
  1136. PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
  1137. PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
  1138. PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
  1139. PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
  1140. PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
  1141. PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
  1142. PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
  1143. PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
  1144. PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
  1145. PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
  1146. PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
  1147. PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
  1148. PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
  1149. PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
  1150. PCLZIP_ERR_UNSUPPORTED_COMPRESSI

Large files files are truncated, but you can click here to view the full file