PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/includes/odtphp/zip/pclzip/pclzip.lib.php

https://bitbucket.org/speedealing/speedealing
PHP | 5693 lines | 2952 code | 915 blank | 1826 comment | 956 complexity | be4ad6fa5c6f10b2267c2f5c37a96995 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT

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

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