PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/pclzip/pclzip.lib.php

https://bitbucket.org/ceu/moodle_demo
PHP | 5747 lines | 2639 code | 815 blank | 2293 comment | 858 complexity | 948ad0868cfb488c755e8d7890a2925c MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, LGPL-2.1

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

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

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