PageRenderTime 538ms CodeModel.GetById 22ms RepoModel.GetById 2ms app.codeStats 1ms

/sondage/admin/classes/pclzip/pclzip-trace.lib.php

https://bitbucket.org/bontiv/insomnia
PHP | 6348 lines | 3731 code | 852 blank | 1765 comment | 893 complexity | 265ebe7cc3a6f696865791790d17afc9 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.1, GPL-3.0, BSD-3-Clause, GPL-2.0

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

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

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