PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/tools/pclzip/pclzip.lib.php

https://bitbucket.org/enurkov/prestashop
PHP | 5694 lines | 2952 code | 915 blank | 1827 comment | 956 complexity | cdf35ff41736804343d6a5b1ac20c69f MD5 | raw file

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

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