/wp-admin/includes/class-pclzip.php

https://bitbucket.org/devbctph/futura_wp · PHP · 5692 lines · 2953 code · 918 blank · 1821 comment · 958 complexity · 59c701d09896cf859689dcf457597084 MD5 · raw file

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