1 | <?php |
---|
2 | // -------------------------------------------------------------------------------- |
---|
3 | // PhpConcept Library - Zip Module 2.6 |
---|
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 | |
---|
26 | if (!defined('PCLZIP_READ_BLOCK_SIZE')) { |
---|
27 | define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); |
---|
28 | } |
---|
29 | |
---|
30 | if (!defined('PCLZIP_SEPARATOR')) { |
---|
31 | define( 'PCLZIP_SEPARATOR', ',' ); |
---|
32 | } |
---|
33 | |
---|
34 | if (!defined('PCLZIP_ERROR_EXTERNAL')) { |
---|
35 | define( 'PCLZIP_ERROR_EXTERNAL', 0 ); |
---|
36 | } |
---|
37 | |
---|
38 | if (!defined('PCLZIP_TEMPORARY_DIR')) { |
---|
39 | define( 'PCLZIP_TEMPORARY_DIR', '' ); |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | $g_pclzip_version = "2.6"; |
---|
44 | |
---|
45 | define( 'PCLZIP_ERR_USER_ABORTED', 2 ); |
---|
46 | define( 'PCLZIP_ERR_NO_ERROR', 0 ); |
---|
47 | define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 ); |
---|
48 | define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 ); |
---|
49 | define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 ); |
---|
50 | define( 'PCLZIP_ERR_MISSING_FILE', -4 ); |
---|
51 | define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 ); |
---|
52 | define( 'PCLZIP_ERR_INVALID_ZIP', -6 ); |
---|
53 | define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 ); |
---|
54 | define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 ); |
---|
55 | define( 'PCLZIP_ERR_BAD_EXTENSION', -9 ); |
---|
56 | define( 'PCLZIP_ERR_BAD_FORMAT', -10 ); |
---|
57 | define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 ); |
---|
58 | define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 ); |
---|
59 | define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 ); |
---|
60 | define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 ); |
---|
61 | define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 ); |
---|
62 | define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 ); |
---|
63 | define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 ); |
---|
64 | define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 ); |
---|
65 | define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 ); |
---|
66 | define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 ); |
---|
67 | define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 ); |
---|
68 | |
---|
69 | define( 'PCLZIP_OPT_PATH', 77001 ); |
---|
70 | define( 'PCLZIP_OPT_ADD_PATH', 77002 ); |
---|
71 | define( 'PCLZIP_OPT_REMOVE_PATH', 77003 ); |
---|
72 | define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 ); |
---|
73 | define( 'PCLZIP_OPT_SET_CHMOD', 77005 ); |
---|
74 | define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 ); |
---|
75 | define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 ); |
---|
76 | define( 'PCLZIP_OPT_BY_NAME', 77008 ); |
---|
77 | define( 'PCLZIP_OPT_BY_INDEX', 77009 ); |
---|
78 | define( 'PCLZIP_OPT_BY_EREG', 77010 ); |
---|
79 | define( 'PCLZIP_OPT_BY_PREG', 77011 ); |
---|
80 | define( 'PCLZIP_OPT_COMMENT', 77012 ); |
---|
81 | define( 'PCLZIP_OPT_ADD_COMMENT', 77013 ); |
---|
82 | define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 ); |
---|
83 | define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 ); |
---|
84 | define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 ); |
---|
85 | define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 ); |
---|
86 | define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); |
---|
87 | |
---|
88 | define( 'PCLZIP_ATT_FILE_NAME', 79001 ); |
---|
89 | define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 ); |
---|
90 | define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 ); |
---|
91 | define( 'PCLZIP_ATT_FILE_MTIME', 79004 ); |
---|
92 | define( 'PCLZIP_ATT_FILE_CONTENT', 79005 ); |
---|
93 | define( 'PCLZIP_ATT_FILE_COMMENT', 79006 ); |
---|
94 | |
---|
95 | define( 'PCLZIP_CB_PRE_EXTRACT', 78001 ); |
---|
96 | define( 'PCLZIP_CB_POST_EXTRACT', 78002 ); |
---|
97 | define( 'PCLZIP_CB_PRE_ADD', 78003 ); |
---|
98 | define( 'PCLZIP_CB_POST_ADD', 78004 ); |
---|
99 | |
---|
100 | |
---|
101 | class PclZip |
---|
102 | { |
---|
103 | var $zipname = ''; |
---|
104 | |
---|
105 | var $zip_fd = 0; |
---|
106 | |
---|
107 | var $error_code = 1; |
---|
108 | var $error_string = ''; |
---|
109 | |
---|
110 | var $magic_quotes_status; |
---|
111 | |
---|
112 | function PclZip($p_zipname) |
---|
113 | { |
---|
114 | |
---|
115 | if (!function_exists('gzopen')) |
---|
116 | { |
---|
117 | die('Abort '.basename(__FILE__).' : Missing zlib extensions'); |
---|
118 | } |
---|
119 | |
---|
120 | $this->zipname = $p_zipname; |
---|
121 | $this->zip_fd = 0; |
---|
122 | $this->magic_quotes_status = -1; |
---|
123 | |
---|
124 | return; |
---|
125 | } |
---|
126 | |
---|
127 | function create($p_filelist) |
---|
128 | { |
---|
129 | $v_result=1; |
---|
130 | |
---|
131 | $this->privErrorReset(); |
---|
132 | |
---|
133 | $v_options = array(); |
---|
134 | $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; |
---|
135 | |
---|
136 | $v_size = func_num_args(); |
---|
137 | |
---|
138 | if ($v_size > 1) { |
---|
139 | $v_arg_list = func_get_args(); |
---|
140 | |
---|
141 | array_shift($v_arg_list); |
---|
142 | $v_size--; |
---|
143 | |
---|
144 | if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
---|
145 | |
---|
146 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
---|
147 | array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
---|
148 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
---|
149 | PCLZIP_OPT_ADD_PATH => 'optional', |
---|
150 | PCLZIP_CB_PRE_ADD => 'optional', |
---|
151 | PCLZIP_CB_POST_ADD => 'optional', |
---|
152 | PCLZIP_OPT_NO_COMPRESSION => 'optional', |
---|
153 | PCLZIP_OPT_COMMENT => 'optional' |
---|
154 | )); |
---|
155 | if ($v_result != 1) { |
---|
156 | return 0; |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | else { |
---|
161 | |
---|
162 | $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0]; |
---|
163 | |
---|
164 | if ($v_size == 2) { |
---|
165 | $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
---|
166 | } |
---|
167 | else if ($v_size > 2) { |
---|
168 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
---|
169 | "Invalid number / type of arguments"); |
---|
170 | return 0; |
---|
171 | } |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | $v_string_list = array(); |
---|
176 | $v_att_list = array(); |
---|
177 | $v_filedescr_list = array(); |
---|
178 | $p_result_list = array(); |
---|
179 | |
---|
180 | if (is_array($p_filelist)) { |
---|
181 | |
---|
182 | if (isset($p_filelist[0]) && is_array($p_filelist[0])) { |
---|
183 | $v_att_list = $p_filelist; |
---|
184 | } |
---|
185 | |
---|
186 | else { |
---|
187 | $v_string_list = $p_filelist; |
---|
188 | } |
---|
189 | } |
---|
190 | |
---|
191 | else if (is_string($p_filelist)) { |
---|
192 | $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); |
---|
193 | } |
---|
194 | |
---|
195 | else { |
---|
196 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); |
---|
197 | return 0; |
---|
198 | } |
---|
199 | |
---|
200 | if (sizeof($v_string_list) != 0) { |
---|
201 | foreach ($v_string_list as $v_string) { |
---|
202 | if ($v_string != '') { |
---|
203 | $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; |
---|
204 | } |
---|
205 | else { |
---|
206 | } |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | $v_supported_attributes |
---|
211 | = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' |
---|
212 | ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
---|
213 | ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
---|
214 | ,PCLZIP_ATT_FILE_MTIME => 'optional' |
---|
215 | ,PCLZIP_ATT_FILE_CONTENT => 'optional' |
---|
216 | ,PCLZIP_ATT_FILE_COMMENT => 'optional' |
---|
217 | ); |
---|
218 | foreach ($v_att_list as $v_entry) { |
---|
219 | $v_result = $this->privFileDescrParseAtt($v_entry, |
---|
220 | $v_filedescr_list[], |
---|
221 | $v_options, |
---|
222 | $v_supported_attributes); |
---|
223 | if ($v_result != 1) { |
---|
224 | return 0; |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); |
---|
229 | if ($v_result != 1) { |
---|
230 | return 0; |
---|
231 | } |
---|
232 | |
---|
233 | $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options); |
---|
234 | if ($v_result != 1) { |
---|
235 | return 0; |
---|
236 | } |
---|
237 | |
---|
238 | return $p_result_list; |
---|
239 | } |
---|
240 | |
---|
241 | function add($p_filelist) |
---|
242 | { |
---|
243 | $v_result=1; |
---|
244 | |
---|
245 | $this->privErrorReset(); |
---|
246 | |
---|
247 | $v_options = array(); |
---|
248 | $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE; |
---|
249 | |
---|
250 | $v_size = func_num_args(); |
---|
251 | |
---|
252 | if ($v_size > 1) { |
---|
253 | $v_arg_list = func_get_args(); |
---|
254 | |
---|
255 | array_shift($v_arg_list); |
---|
256 | $v_size--; |
---|
257 | |
---|
258 | if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
---|
259 | |
---|
260 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
---|
261 | array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
---|
262 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
---|
263 | PCLZIP_OPT_ADD_PATH => 'optional', |
---|
264 | PCLZIP_CB_PRE_ADD => 'optional', |
---|
265 | PCLZIP_CB_POST_ADD => 'optional', |
---|
266 | PCLZIP_OPT_NO_COMPRESSION => 'optional', |
---|
267 | PCLZIP_OPT_COMMENT => 'optional', |
---|
268 | PCLZIP_OPT_ADD_COMMENT => 'optional', |
---|
269 | PCLZIP_OPT_PREPEND_COMMENT => 'optional' |
---|
270 | )); |
---|
271 | if ($v_result != 1) { |
---|
272 | return 0; |
---|
273 | } |
---|
274 | } |
---|
275 | |
---|
276 | else { |
---|
277 | |
---|
278 | $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0]; |
---|
279 | |
---|
280 | if ($v_size == 2) { |
---|
281 | $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
---|
282 | } |
---|
283 | else if ($v_size > 2) { |
---|
284 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
---|
285 | |
---|
286 | return 0; |
---|
287 | } |
---|
288 | } |
---|
289 | } |
---|
290 | |
---|
291 | $v_string_list = array(); |
---|
292 | $v_att_list = array(); |
---|
293 | $v_filedescr_list = array(); |
---|
294 | $p_result_list = array(); |
---|
295 | |
---|
296 | if (is_array($p_filelist)) { |
---|
297 | |
---|
298 | if (isset($p_filelist[0]) && is_array($p_filelist[0])) { |
---|
299 | $v_att_list = $p_filelist; |
---|
300 | } |
---|
301 | |
---|
302 | else { |
---|
303 | $v_string_list = $p_filelist; |
---|
304 | } |
---|
305 | } |
---|
306 | |
---|
307 | else if (is_string($p_filelist)) { |
---|
308 | $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); |
---|
309 | } |
---|
310 | |
---|
311 | else { |
---|
312 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); |
---|
313 | return 0; |
---|
314 | } |
---|
315 | |
---|
316 | if (sizeof($v_string_list) != 0) { |
---|
317 | foreach ($v_string_list as $v_string) { |
---|
318 | $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; |
---|
319 | } |
---|
320 | } |
---|
321 | |
---|
322 | $v_supported_attributes |
---|
323 | = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' |
---|
324 | ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
---|
325 | ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
---|
326 | ,PCLZIP_ATT_FILE_MTIME => 'optional' |
---|
327 | ,PCLZIP_ATT_FILE_CONTENT => 'optional' |
---|
328 | ,PCLZIP_ATT_FILE_COMMENT => 'optional' |
---|
329 | ); |
---|
330 | foreach ($v_att_list as $v_entry) { |
---|
331 | $v_result = $this->privFileDescrParseAtt($v_entry, |
---|
332 | $v_filedescr_list[], |
---|
333 | $v_options, |
---|
334 | $v_supported_attributes); |
---|
335 | if ($v_result != 1) { |
---|
336 | return 0; |
---|
337 | } |
---|
338 | } |
---|
339 | |
---|
340 | $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); |
---|
341 | if ($v_result != 1) { |
---|
342 | return 0; |
---|
343 | } |
---|
344 | |
---|
345 | $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options); |
---|
346 | if ($v_result != 1) { |
---|
347 | return 0; |
---|
348 | } |
---|
349 | |
---|
350 | return $p_result_list; |
---|
351 | } |
---|
352 | |
---|
353 | function listContent() |
---|
354 | { |
---|
355 | $v_result=1; |
---|
356 | |
---|
357 | $this->privErrorReset(); |
---|
358 | |
---|
359 | if (!$this->privCheckFormat()) { |
---|
360 | return(0); |
---|
361 | } |
---|
362 | |
---|
363 | $p_list = array(); |
---|
364 | if (($v_result = $this->privList($p_list)) != 1) |
---|
365 | { |
---|
366 | unset($p_list); |
---|
367 | return(0); |
---|
368 | } |
---|
369 | |
---|
370 | return $p_list; |
---|
371 | } |
---|
372 | |
---|
373 | function extract() |
---|
374 | { |
---|
375 | $v_result=1; |
---|
376 | |
---|
377 | $this->privErrorReset(); |
---|
378 | |
---|
379 | if (!$this->privCheckFormat()) { |
---|
380 | return(0); |
---|
381 | } |
---|
382 | |
---|
383 | $v_options = array(); |
---|
384 | $v_path = ''; |
---|
385 | $v_remove_path = ""; |
---|
386 | $v_remove_all_path = false; |
---|
387 | |
---|
388 | $v_size = func_num_args(); |
---|
389 | |
---|
390 | $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
---|
391 | |
---|
392 | if ($v_size > 0) { |
---|
393 | $v_arg_list = func_get_args(); |
---|
394 | |
---|
395 | if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
---|
396 | |
---|
397 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
---|
398 | array (PCLZIP_OPT_PATH => 'optional', |
---|
399 | PCLZIP_OPT_REMOVE_PATH => 'optional', |
---|
400 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
---|
401 | PCLZIP_OPT_ADD_PATH => 'optional', |
---|
402 | PCLZIP_CB_PRE_EXTRACT => 'optional', |
---|
403 | PCLZIP_CB_POST_EXTRACT => 'optional', |
---|
404 | PCLZIP_OPT_SET_CHMOD => 'optional', |
---|
405 | PCLZIP_OPT_BY_NAME => 'optional', |
---|
406 | PCLZIP_OPT_BY_EREG => 'optional', |
---|
407 | PCLZIP_OPT_BY_PREG => 'optional', |
---|
408 | PCLZIP_OPT_BY_INDEX => 'optional', |
---|
409 | PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', |
---|
410 | PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional', |
---|
411 | PCLZIP_OPT_REPLACE_NEWER => 'optional' |
---|
412 | ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' |
---|
413 | ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' |
---|
414 | )); |
---|
415 | if ($v_result != 1) { |
---|
416 | return 0; |
---|
417 | } |
---|
418 | |
---|
419 | if (isset($v_options[PCLZIP_OPT_PATH])) { |
---|
420 | $v_path = $v_options[PCLZIP_OPT_PATH]; |
---|
421 | } |
---|
422 | if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { |
---|
423 | $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; |
---|
424 | } |
---|
425 | if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
---|
426 | $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
---|
427 | } |
---|
428 | if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { |
---|
429 | if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { |
---|
430 | $v_path .= '/'; |
---|
431 | } |
---|
432 | $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; |
---|
433 | } |
---|
434 | } |
---|
435 | |
---|
436 | else { |
---|
437 | |
---|
438 | $v_path = $v_arg_list[0]; |
---|
439 | |
---|
440 | if ($v_size == 2) { |
---|
441 | $v_remove_path = $v_arg_list[1]; |
---|
442 | } |
---|
443 | else if ($v_size > 2) { |
---|
444 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
---|
445 | |
---|
446 | return 0; |
---|
447 | } |
---|
448 | } |
---|
449 | } |
---|
450 | |
---|
451 | |
---|
452 | $p_list = array(); |
---|
453 | $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, |
---|
454 | $v_remove_all_path, $v_options); |
---|
455 | if ($v_result < 1) { |
---|
456 | unset($p_list); |
---|
457 | return(0); |
---|
458 | } |
---|
459 | |
---|
460 | return $p_list; |
---|
461 | } |
---|
462 | |
---|
463 | |
---|
464 | function extractByIndex($p_index) |
---|
465 | { |
---|
466 | $v_result=1; |
---|
467 | |
---|
468 | $this->privErrorReset(); |
---|
469 | |
---|
470 | if (!$this->privCheckFormat()) { |
---|
471 | return(0); |
---|
472 | } |
---|
473 | |
---|
474 | $v_options = array(); |
---|
475 | $v_path = ''; |
---|
476 | $v_remove_path = ""; |
---|
477 | $v_remove_all_path = false; |
---|
478 | |
---|
479 | $v_size = func_num_args(); |
---|
480 | |
---|
481 | $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
---|
482 | |
---|
483 | if ($v_size > 1) { |
---|
484 | $v_arg_list = func_get_args(); |
---|
485 | |
---|
486 | array_shift($v_arg_list); |
---|
487 | $v_size--; |
---|
488 | |
---|
489 | if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
---|
490 | |
---|
491 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
---|
492 | array (PCLZIP_OPT_PATH => 'optional', |
---|
493 | PCLZIP_OPT_REMOVE_PATH => 'optional', |
---|
494 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
---|
495 | PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', |
---|
496 | PCLZIP_OPT_ADD_PATH => 'optional', |
---|
497 | PCLZIP_CB_PRE_EXTRACT => 'optional', |
---|
498 | PCLZIP_CB_POST_EXTRACT => 'optional', |
---|
499 | PCLZIP_OPT_SET_CHMOD => 'optional', |
---|
500 | PCLZIP_OPT_REPLACE_NEWER => 'optional' |
---|
501 | ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' |
---|
502 | ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional' |
---|
503 | )); |
---|
504 | if ($v_result != 1) { |
---|
505 | return 0; |
---|
506 | } |
---|
507 | |
---|
508 | if (isset($v_options[PCLZIP_OPT_PATH])) { |
---|
509 | $v_path = $v_options[PCLZIP_OPT_PATH]; |
---|
510 | } |
---|
511 | if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { |
---|
512 | $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; |
---|
513 | } |
---|
514 | if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
---|
515 | $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
---|
516 | } |
---|
517 | if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { |
---|
518 | if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { |
---|
519 | $v_path .= '/'; |
---|
520 | } |
---|
521 | $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; |
---|
522 | } |
---|
523 | if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { |
---|
524 | $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
---|
525 | } |
---|
526 | else { |
---|
527 | } |
---|
528 | } |
---|
529 | |
---|
530 | else { |
---|
531 | |
---|
532 | $v_path = $v_arg_list[0]; |
---|
533 | |
---|
534 | if ($v_size == 2) { |
---|
535 | $v_remove_path = $v_arg_list[1]; |
---|
536 | } |
---|
537 | else if ($v_size > 2) { |
---|
538 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
---|
539 | |
---|
540 | return 0; |
---|
541 | } |
---|
542 | } |
---|
543 | } |
---|
544 | |
---|
545 | |
---|
546 | $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index); |
---|
547 | $v_options_trick = array(); |
---|
548 | $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, |
---|
549 | array (PCLZIP_OPT_BY_INDEX => 'optional' )); |
---|
550 | if ($v_result != 1) { |
---|
551 | return 0; |
---|
552 | } |
---|
553 | $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX]; |
---|
554 | |
---|
555 | if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) { |
---|
556 | return(0); |
---|
557 | } |
---|
558 | |
---|
559 | return $p_list; |
---|
560 | } |
---|
561 | |
---|
562 | function delete() |
---|
563 | { |
---|
564 | $v_result=1; |
---|
565 | |
---|
566 | $this->privErrorReset(); |
---|
567 | |
---|
568 | if (!$this->privCheckFormat()) { |
---|
569 | return(0); |
---|
570 | } |
---|
571 | |
---|
572 | $v_options = array(); |
---|
573 | |
---|
574 | $v_size = func_num_args(); |
---|
575 | |
---|
576 | if ($v_size > 0) { |
---|
577 | $v_arg_list = func_get_args(); |
---|
578 | |
---|
579 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
---|
580 | array (PCLZIP_OPT_BY_NAME => 'optional', |
---|
581 | PCLZIP_OPT_BY_EREG => 'optional', |
---|
582 | PCLZIP_OPT_BY_PREG => 'optional', |
---|
583 | PCLZIP_OPT_BY_INDEX => 'optional' )); |
---|
584 | if ($v_result != 1) { |
---|
585 | return 0; |
---|
586 | } |
---|
587 | } |
---|
588 | |
---|
589 | $this->privDisableMagicQuotes(); |
---|
590 | |
---|
591 | $v_list = array(); |
---|
592 | if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) { |
---|
593 | $this->privSwapBackMagicQuotes(); |
---|
594 | unset($v_list); |
---|
595 | return(0); |
---|
596 | } |
---|
597 | |
---|
598 | $this->privSwapBackMagicQuotes(); |
---|
599 | |
---|
600 | return $v_list; |
---|
601 | } |
---|
602 | |
---|
603 | function deleteByIndex($p_index) |
---|
604 | { |
---|
605 | |
---|
606 | $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); |
---|
607 | |
---|
608 | return $p_list; |
---|
609 | } |
---|
610 | |
---|
611 | function properties() |
---|
612 | { |
---|
613 | |
---|
614 | $this->privErrorReset(); |
---|
615 | |
---|
616 | $this->privDisableMagicQuotes(); |
---|
617 | |
---|
618 | if (!$this->privCheckFormat()) { |
---|
619 | $this->privSwapBackMagicQuotes(); |
---|
620 | return(0); |
---|
621 | } |
---|
622 | |
---|
623 | $v_prop = array(); |
---|
624 | $v_prop['comment'] = ''; |
---|
625 | $v_prop['nb'] = 0; |
---|
626 | $v_prop['status'] = 'not_exist'; |
---|
627 | |
---|
628 | if (@is_file($this->zipname)) |
---|
629 | { |
---|
630 | if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) |
---|
631 | { |
---|
632 | $this->privSwapBackMagicQuotes(); |
---|
633 | |
---|
634 | PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
---|
635 | |
---|
636 | return 0; |
---|
637 | } |
---|
638 | |
---|
639 | $v_central_dir = array(); |
---|
640 | if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
---|
641 | { |
---|
642 | $this->privSwapBackMagicQuotes(); |
---|
643 | return 0; |
---|
644 | } |
---|
645 | |
---|
646 | $this->privCloseFd(); |
---|
647 | |
---|
648 | $v_prop['comment'] = $v_central_dir['comment']; |
---|
649 | $v_prop['nb'] = $v_central_dir['entries']; |
---|
650 | $v_prop['status'] = 'ok'; |
---|
651 | } |
---|
652 | |
---|
653 | $this->privSwapBackMagicQuotes(); |
---|
654 | |
---|
655 | return $v_prop; |
---|
656 | } |
---|
657 | |
---|
658 | function duplicate($p_archive) |
---|
659 | { |
---|
660 | $v_result = 1; |
---|
661 | |
---|
662 | $this->privErrorReset(); |
---|
663 | |
---|
664 | if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) |
---|
665 | { |
---|
666 | |
---|
667 | $v_result = $this->privDuplicate($p_archive->zipname); |
---|
668 | } |
---|
669 | |
---|
670 | else if (is_string($p_archive)) |
---|
671 | { |
---|
672 | |
---|
673 | if (!is_file($p_archive)) { |
---|
674 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'"); |
---|
675 | $v_result = PCLZIP_ERR_MISSING_FILE; |
---|
676 | } |
---|
677 | else { |
---|
678 | $v_result = $this->privDuplicate($p_archive); |
---|
679 | } |
---|
680 | } |
---|
681 | |
---|
682 | else |
---|
683 | { |
---|
684 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); |
---|
685 | $v_result = PCLZIP_ERR_INVALID_PARAMETER; |
---|
686 | } |
---|
687 | |
---|
688 | return $v_result; |
---|
689 | } |
---|
690 | |
---|
691 | function merge($p_archive_to_add) |
---|
692 | { |
---|
693 | $v_result = 1; |
---|
694 | |
---|
695 | $this->privErrorReset(); |
---|
696 | |
---|
697 | if (!$this->privCheckFormat()) { |
---|
698 | return(0); |
---|
699 | } |
---|
700 | |
---|
701 | if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) |
---|
702 | { |
---|
703 | |
---|
704 | $v_result = $this->privMerge($p_archive_to_add); |
---|
705 | } |
---|
706 | |
---|
707 | else if (is_string($p_archive_to_add)) |
---|
708 | { |
---|
709 | |
---|
710 | $v_object_archive = new PclZip($p_archive_to_add); |
---|
711 | |
---|
712 | $v_result = $this->privMerge($v_object_archive); |
---|
713 | } |
---|
714 | |
---|
715 | else |
---|
716 | { |
---|
717 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); |
---|
718 | $v_result = PCLZIP_ERR_INVALID_PARAMETER; |
---|
719 | } |
---|
720 | |
---|
721 | return $v_result; |
---|
722 | } |
---|
723 | |
---|
724 | |
---|
725 | |
---|
726 | function errorCode() |
---|
727 | { |
---|
728 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
---|
729 | return(PclErrorCode()); |
---|
730 | } |
---|
731 | else { |
---|
732 | return($this->error_code); |
---|
733 | } |
---|
734 | } |
---|
735 | |
---|
736 | function errorName($p_with_code=false) |
---|
737 | { |
---|
738 | $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', |
---|
739 | PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', |
---|
740 | PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', |
---|
741 | PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', |
---|
742 | PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE', |
---|
743 | PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG', |
---|
744 | PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP', |
---|
745 | PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE', |
---|
746 | PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL', |
---|
747 | PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION', |
---|
748 | PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT', |
---|
749 | PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL', |
---|
750 | PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL', |
---|
751 | PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM', |
---|
752 | PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', |
---|
753 | PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE', |
---|
754 | PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE', |
---|
755 | PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', |
---|
756 | PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION' |
---|
757 | ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE' |
---|
758 | ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION' |
---|
759 | ); |
---|
760 | |
---|
761 | if (isset($v_name[$this->error_code])) { |
---|
762 | $v_value = $v_name[$this->error_code]; |
---|
763 | } |
---|
764 | else { |
---|
765 | $v_value = 'NoName'; |
---|
766 | } |
---|
767 | |
---|
768 | if ($p_with_code) { |
---|
769 | return($v_value.' ('.$this->error_code.')'); |
---|
770 | } |
---|
771 | else { |
---|
772 | return($v_value); |
---|
773 | } |
---|
774 | } |
---|
775 | |
---|
776 | function errorInfo($p_full=false) |
---|
777 | { |
---|
778 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
---|
779 | return(PclErrorString()); |
---|
780 | } |
---|
781 | else { |
---|
782 | if ($p_full) { |
---|
783 | return($this->errorName(true)." : ".$this->error_string); |
---|
784 | } |
---|
785 | else { |
---|
786 | return($this->error_string." [code ".$this->error_code."]"); |
---|
787 | } |
---|
788 | } |
---|
789 | } |
---|
790 | |
---|
791 | |
---|
792 | |
---|
793 | |
---|
794 | |
---|
795 | function privCheckFormat($p_level=0) |
---|
796 | { |
---|
797 | $v_result = true; |
---|
798 | |
---|
799 | clearstatcache(); |
---|
800 | |
---|
801 | $this->privErrorReset(); |
---|
802 | |
---|
803 | if (!is_file($this->zipname)) { |
---|
804 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); |
---|
805 | return(false); |
---|
806 | } |
---|
807 | |
---|
808 | if (!is_readable($this->zipname)) { |
---|
809 | PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); |
---|
810 | return(false); |
---|
811 | } |
---|
812 | |
---|
813 | |
---|
814 | |
---|
815 | |
---|
816 | return $v_result; |
---|
817 | } |
---|
818 | |
---|
819 | function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) |
---|
820 | { |
---|
821 | $v_result=1; |
---|
822 | |
---|
823 | $i=0; |
---|
824 | while ($i<$p_size) { |
---|
825 | |
---|
826 | if (!isset($v_requested_options[$p_options_list[$i]])) { |
---|
827 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); |
---|
828 | |
---|
829 | return PclZip::errorCode(); |
---|
830 | } |
---|
831 | |
---|
832 | switch ($p_options_list[$i]) { |
---|
833 | case PCLZIP_OPT_PATH : |
---|
834 | case PCLZIP_OPT_REMOVE_PATH : |
---|
835 | case PCLZIP_OPT_ADD_PATH : |
---|
836 | if (($i+1) >= $p_size) { |
---|
837 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
838 | |
---|
839 | return PclZip::errorCode(); |
---|
840 | } |
---|
841 | |
---|
842 | $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
---|
843 | $i++; |
---|
844 | break; |
---|
845 | |
---|
846 | case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : |
---|
847 | if (($i+1) >= $p_size) { |
---|
848 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
849 | |
---|
850 | return PclZip::errorCode(); |
---|
851 | } |
---|
852 | |
---|
853 | if ( is_string($p_options_list[$i+1]) |
---|
854 | && ($p_options_list[$i+1] != '')) { |
---|
855 | $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
---|
856 | $i++; |
---|
857 | } |
---|
858 | else { |
---|
859 | } |
---|
860 | break; |
---|
861 | |
---|
862 | case PCLZIP_OPT_BY_NAME : |
---|
863 | if (($i+1) >= $p_size) { |
---|
864 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
865 | |
---|
866 | return PclZip::errorCode(); |
---|
867 | } |
---|
868 | |
---|
869 | if (is_string($p_options_list[$i+1])) { |
---|
870 | $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; |
---|
871 | } |
---|
872 | else if (is_array($p_options_list[$i+1])) { |
---|
873 | $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
---|
874 | } |
---|
875 | else { |
---|
876 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
877 | |
---|
878 | return PclZip::errorCode(); |
---|
879 | } |
---|
880 | $i++; |
---|
881 | break; |
---|
882 | |
---|
883 | case PCLZIP_OPT_BY_EREG : |
---|
884 | case PCLZIP_OPT_BY_PREG : |
---|
885 | if (($i+1) >= $p_size) { |
---|
886 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
887 | |
---|
888 | return PclZip::errorCode(); |
---|
889 | } |
---|
890 | |
---|
891 | if (is_string($p_options_list[$i+1])) { |
---|
892 | $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
---|
893 | } |
---|
894 | else { |
---|
895 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
896 | |
---|
897 | return PclZip::errorCode(); |
---|
898 | } |
---|
899 | $i++; |
---|
900 | break; |
---|
901 | |
---|
902 | case PCLZIP_OPT_COMMENT : |
---|
903 | case PCLZIP_OPT_ADD_COMMENT : |
---|
904 | case PCLZIP_OPT_PREPEND_COMMENT : |
---|
905 | if (($i+1) >= $p_size) { |
---|
906 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, |
---|
907 | "Missing parameter value for option '" |
---|
908 | .PclZipUtilOptionText($p_options_list[$i]) |
---|
909 | ."'"); |
---|
910 | |
---|
911 | return PclZip::errorCode(); |
---|
912 | } |
---|
913 | |
---|
914 | if (is_string($p_options_list[$i+1])) { |
---|
915 | $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
---|
916 | } |
---|
917 | else { |
---|
918 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, |
---|
919 | "Wrong parameter value for option '" |
---|
920 | .PclZipUtilOptionText($p_options_list[$i]) |
---|
921 | ."'"); |
---|
922 | |
---|
923 | return PclZip::errorCode(); |
---|
924 | } |
---|
925 | $i++; |
---|
926 | break; |
---|
927 | |
---|
928 | case PCLZIP_OPT_BY_INDEX : |
---|
929 | if (($i+1) >= $p_size) { |
---|
930 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
931 | |
---|
932 | return PclZip::errorCode(); |
---|
933 | } |
---|
934 | |
---|
935 | $v_work_list = array(); |
---|
936 | if (is_string($p_options_list[$i+1])) { |
---|
937 | |
---|
938 | $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); |
---|
939 | |
---|
940 | $v_work_list = explode(",", $p_options_list[$i+1]); |
---|
941 | } |
---|
942 | else if (is_integer($p_options_list[$i+1])) { |
---|
943 | $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; |
---|
944 | } |
---|
945 | else if (is_array($p_options_list[$i+1])) { |
---|
946 | $v_work_list = $p_options_list[$i+1]; |
---|
947 | } |
---|
948 | else { |
---|
949 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
950 | |
---|
951 | return PclZip::errorCode(); |
---|
952 | } |
---|
953 | |
---|
954 | $v_sort_flag=false; |
---|
955 | $v_sort_value=0; |
---|
956 | for ($j=0; $j<sizeof($v_work_list); $j++) { |
---|
957 | $v_item_list = explode("-", $v_work_list[$j]); |
---|
958 | $v_size_item_list = sizeof($v_item_list); |
---|
959 | |
---|
960 | |
---|
961 | if ($v_size_item_list == 1) { |
---|
962 | $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
---|
963 | $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; |
---|
964 | } |
---|
965 | elseif ($v_size_item_list == 2) { |
---|
966 | $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
---|
967 | $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; |
---|
968 | } |
---|
969 | else { |
---|
970 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
971 | |
---|
972 | return PclZip::errorCode(); |
---|
973 | } |
---|
974 | |
---|
975 | |
---|
976 | if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { |
---|
977 | $v_sort_flag=true; |
---|
978 | |
---|
979 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
980 | |
---|
981 | return PclZip::errorCode(); |
---|
982 | } |
---|
983 | $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; |
---|
984 | } |
---|
985 | |
---|
986 | if ($v_sort_flag) { |
---|
987 | } |
---|
988 | |
---|
989 | $i++; |
---|
990 | break; |
---|
991 | |
---|
992 | case PCLZIP_OPT_REMOVE_ALL_PATH : |
---|
993 | case PCLZIP_OPT_EXTRACT_AS_STRING : |
---|
994 | case PCLZIP_OPT_NO_COMPRESSION : |
---|
995 | case PCLZIP_OPT_EXTRACT_IN_OUTPUT : |
---|
996 | case PCLZIP_OPT_REPLACE_NEWER : |
---|
997 | case PCLZIP_OPT_STOP_ON_ERROR : |
---|
998 | $v_result_list[$p_options_list[$i]] = true; |
---|
999 | break; |
---|
1000 | |
---|
1001 | case PCLZIP_OPT_SET_CHMOD : |
---|
1002 | if (($i+1) >= $p_size) { |
---|
1003 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
1004 | |
---|
1005 | return PclZip::errorCode(); |
---|
1006 | } |
---|
1007 | |
---|
1008 | $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
---|
1009 | $i++; |
---|
1010 | break; |
---|
1011 | |
---|
1012 | case PCLZIP_CB_PRE_EXTRACT : |
---|
1013 | case PCLZIP_CB_POST_EXTRACT : |
---|
1014 | case PCLZIP_CB_PRE_ADD : |
---|
1015 | case PCLZIP_CB_POST_ADD : |
---|
1016 | |
---|
1017 | if (($i+1) >= $p_size) { |
---|
1018 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
1019 | |
---|
1020 | return PclZip::errorCode(); |
---|
1021 | } |
---|
1022 | |
---|
1023 | $v_function_name = $p_options_list[$i+1]; |
---|
1024 | |
---|
1025 | if (!function_exists($v_function_name)) { |
---|
1026 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
---|
1027 | |
---|
1028 | return PclZip::errorCode(); |
---|
1029 | } |
---|
1030 | |
---|
1031 | $v_result_list[$p_options_list[$i]] = $v_function_name; |
---|
1032 | $i++; |
---|
1033 | break; |
---|
1034 | |
---|
1035 | default : |
---|
1036 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
---|
1037 | "Unknown parameter '" |
---|
1038 | .$p_options_list[$i]."'"); |
---|
1039 | |
---|
1040 | return PclZip::errorCode(); |
---|
1041 | } |
---|
1042 | |
---|
1043 | $i++; |
---|
1044 | } |
---|
1045 | |
---|
1046 | if ($v_requested_options !== false) { |
---|
1047 | for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
---|
1048 | if ($v_requested_options[$key] == 'mandatory') { |
---|
1049 | if (!isset($v_result_list[$key])) { |
---|
1050 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
---|
1051 | |
---|
1052 | return PclZip::errorCode(); |
---|
1053 | } |
---|
1054 | } |
---|
1055 | } |
---|
1056 | } |
---|
1057 | |
---|
1058 | return $v_result; |
---|
1059 | } |
---|
1060 | |
---|
1061 | function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) |
---|
1062 | { |
---|
1063 | $v_result=1; |
---|
1064 | |
---|
1065 | foreach ($p_file_list as $v_key => $v_value) { |
---|
1066 | |
---|
1067 | if (!isset($v_requested_options[$v_key])) { |
---|
1068 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); |
---|
1069 | |
---|
1070 | return PclZip::errorCode(); |
---|
1071 | } |
---|
1072 | |
---|
1073 | switch ($v_key) { |
---|
1074 | case PCLZIP_ATT_FILE_NAME : |
---|
1075 | if (!is_string($v_value)) { |
---|
1076 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
---|
1077 | return PclZip::errorCode(); |
---|
1078 | } |
---|
1079 | |
---|
1080 | $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); |
---|
1081 | |
---|
1082 | if ($p_filedescr['filename'] == '') { |
---|
1083 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
---|
1084 | return PclZip::errorCode(); |
---|
1085 | } |
---|
1086 | |
---|
1087 | break; |
---|
1088 | |
---|
1089 | case PCLZIP_ATT_FILE_NEW_SHORT_NAME : |
---|
1090 | if (!is_string($v_value)) { |
---|
1091 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
---|
1092 | return PclZip::errorCode(); |
---|
1093 | } |
---|
1094 | |
---|
1095 | $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); |
---|
1096 | |
---|
1097 | if ($p_filedescr['new_short_name'] == '') { |
---|
1098 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
---|
1099 | return PclZip::errorCode(); |
---|
1100 | } |
---|
1101 | break; |
---|
1102 | |
---|
1103 | case PCLZIP_ATT_FILE_NEW_FULL_NAME : |
---|
1104 | if (!is_string($v_value)) { |
---|
1105 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
---|
1106 | return PclZip::errorCode(); |
---|
1107 | } |
---|
1108 | |
---|
1109 | $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); |
---|
1110 | |
---|
1111 | if ($p_filedescr['new_full_name'] == '') { |
---|
1112 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
---|
1113 | return PclZip::errorCode(); |
---|
1114 | } |
---|
1115 | break; |
---|
1116 | |
---|
1117 | case PCLZIP_ATT_FILE_COMMENT : |
---|
1118 | if (!is_string($v_value)) { |
---|
1119 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
---|
1120 | return PclZip::errorCode(); |
---|
1121 | } |
---|
1122 | |
---|
1123 | $p_filedescr['comment'] = $v_value; |
---|
1124 | break; |
---|
1125 | |
---|
1126 | case PCLZIP_ATT_FILE_MTIME : |
---|
1127 | if (!is_integer($v_value)) { |
---|
1128 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
---|
1129 | return PclZip::errorCode(); |
---|
1130 | } |
---|
1131 | |
---|
1132 | $p_filedescr['mtime'] = $v_value; |
---|
1133 | break; |
---|
1134 | |
---|
1135 | case PCLZIP_ATT_FILE_CONTENT : |
---|
1136 | $p_filedescr['content'] = $v_value; |
---|
1137 | break; |
---|
1138 | |
---|
1139 | default : |
---|
1140 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
---|
1141 | "Unknown parameter '".$v_key."'"); |
---|
1142 | |
---|
1143 | return PclZip::errorCode(); |
---|
1144 | } |
---|
1145 | |
---|
1146 | if ($v_requested_options !== false) { |
---|
1147 | for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
---|
1148 | if ($v_requested_options[$key] == 'mandatory') { |
---|
1149 | if (!isset($p_file_list[$key])) { |
---|
1150 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
---|
1151 | return PclZip::errorCode(); |
---|
1152 | } |
---|
1153 | } |
---|
1154 | } |
---|
1155 | } |
---|
1156 | |
---|
1157 | } |
---|
1158 | |
---|
1159 | return $v_result; |
---|
1160 | } |
---|
1161 | |
---|
1162 | function privFileDescrExpand(&$p_filedescr_list, &$p_options) |
---|
1163 | { |
---|
1164 | $v_result=1; |
---|
1165 | |
---|
1166 | $v_result_list = array(); |
---|
1167 | |
---|
1168 | for ($i=0; $i<sizeof($p_filedescr_list); $i++) { |
---|
1169 | |
---|
1170 | $v_descr = $p_filedescr_list[$i]; |
---|
1171 | |
---|
1172 | $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename']); |
---|
1173 | $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); |
---|
1174 | |
---|
1175 | if (file_exists($v_descr['filename'])) { |
---|
1176 | if (@is_file($v_descr['filename'])) { |
---|
1177 | $v_descr['type'] = 'file'; |
---|
1178 | } |
---|
1179 | else if (@is_dir($v_descr['filename'])) { |
---|
1180 | $v_descr['type'] = 'folder'; |
---|
1181 | } |
---|
1182 | else if (@is_link($v_descr['filename'])) { |
---|
1183 | continue; |
---|
1184 | } |
---|
1185 | else { |
---|
1186 | continue; |
---|
1187 | } |
---|
1188 | } |
---|
1189 | |
---|
1190 | else if (isset($v_descr['content'])) { |
---|
1191 | $v_descr['type'] = 'virtual_file'; |
---|
1192 | } |
---|
1193 | |
---|
1194 | else { |
---|
1195 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exists"); |
---|
1196 | |
---|
1197 | return PclZip::errorCode(); |
---|
1198 | } |
---|
1199 | |
---|
1200 | $this->privCalculateStoredFilename($v_descr, $p_options); |
---|
1201 | |
---|
1202 | $v_result_list[sizeof($v_result_list)] = $v_descr; |
---|
1203 | |
---|
1204 | if ($v_descr['type'] == 'folder') { |
---|
1205 | $v_dirlist_descr = array(); |
---|
1206 | $v_dirlist_nb = 0; |
---|
1207 | if ($v_folder_handler = @opendir($v_descr['filename'])) { |
---|
1208 | while (($v_item_handler = @readdir($v_folder_handler)) !== false) { |
---|
1209 | |
---|
1210 | if (($v_item_handler == '.') || ($v_item_handler == '..')) { |
---|
1211 | continue; |
---|
1212 | } |
---|
1213 | |
---|
1214 | $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler; |
---|
1215 | |
---|
1216 | if ($v_descr['stored_filename'] != $v_descr['filename']) { |
---|
1217 | if ($v_descr['stored_filename'] != '') { |
---|
1218 | $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; |
---|
1219 | } |
---|
1220 | else { |
---|
1221 | $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; |
---|
1222 | } |
---|
1223 | } |
---|
1224 | |
---|
1225 | $v_dirlist_nb++; |
---|
1226 | } |
---|
1227 | |
---|
1228 | @closedir($v_folder_handler); |
---|
1229 | } |
---|
1230 | else { |
---|
1231 | } |
---|
1232 | |
---|
1233 | if ($v_dirlist_nb != 0) { |
---|
1234 | if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { |
---|
1235 | return $v_result; |
---|
1236 | } |
---|
1237 | |
---|
1238 | $v_result_list = array_merge($v_result_list, $v_dirlist_descr); |
---|
1239 | } |
---|
1240 | else { |
---|
1241 | } |
---|
1242 | |
---|
1243 | unset($v_dirlist_descr); |
---|
1244 | } |
---|
1245 | } |
---|
1246 | |
---|
1247 | $p_filedescr_list = $v_result_list; |
---|
1248 | |
---|
1249 | return $v_result; |
---|
1250 | } |
---|
1251 | |
---|
1252 | function privCreate($p_filedescr_list, &$p_result_list, &$p_options) |
---|
1253 | { |
---|
1254 | $v_result=1; |
---|
1255 | $v_list_detail = array(); |
---|
1256 | |
---|
1257 | $this->privDisableMagicQuotes(); |
---|
1258 | |
---|
1259 | if (($v_result = $this->privOpenFd('wb')) != 1) |
---|
1260 | { |
---|
1261 | return $v_result; |
---|
1262 | } |
---|
1263 | |
---|
1264 | $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options); |
---|
1265 | |
---|
1266 | $this->privCloseFd(); |
---|
1267 | |
---|
1268 | $this->privSwapBackMagicQuotes(); |
---|
1269 | |
---|
1270 | return $v_result; |
---|
1271 | } |
---|
1272 | |
---|
1273 | function privAdd($p_filedescr_list, &$p_result_list, &$p_options) |
---|
1274 | { |
---|
1275 | $v_result=1; |
---|
1276 | $v_list_detail = array(); |
---|
1277 | |
---|
1278 | if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) |
---|
1279 | { |
---|
1280 | |
---|
1281 | $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); |
---|
1282 | |
---|
1283 | return $v_result; |
---|
1284 | } |
---|
1285 | $this->privDisableMagicQuotes(); |
---|
1286 | |
---|
1287 | if (($v_result=$this->privOpenFd('rb')) != 1) |
---|
1288 | { |
---|
1289 | $this->privSwapBackMagicQuotes(); |
---|
1290 | |
---|
1291 | return $v_result; |
---|
1292 | } |
---|
1293 | |
---|
1294 | $v_central_dir = array(); |
---|
1295 | if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
---|
1296 | { |
---|
1297 | $this->privCloseFd(); |
---|
1298 | $this->privSwapBackMagicQuotes(); |
---|
1299 | return $v_result; |
---|
1300 | } |
---|
1301 | |
---|
1302 | @rewind($this->zip_fd); |
---|
1303 | |
---|
1304 | $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
---|
1305 | |
---|
1306 | if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
---|
1307 | { |
---|
1308 | $this->privCloseFd(); |
---|
1309 | $this->privSwapBackMagicQuotes(); |
---|
1310 | |
---|
1311 | PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
---|
1312 | |
---|
1313 | return PclZip::errorCode(); |
---|
1314 | } |
---|
1315 | |
---|
1316 | $v_size = $v_central_dir['offset']; |
---|
1317 | while ($v_size != 0) |
---|
1318 | { |
---|
1319 | $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
---|
1320 | $v_buffer = fread($this->zip_fd, $v_read_size); |
---|
1321 | @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
---|
1322 | $v_size -= $v_read_size; |
---|
1323 | } |
---|
1324 | |
---|
1325 | $v_swap = $this->zip_fd; |
---|
1326 | $this->zip_fd = $v_zip_temp_fd; |
---|
1327 | $v_zip_temp_fd = $v_swap; |
---|
1328 | |
---|
1329 | $v_header_list = array(); |
---|
1330 | if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) |
---|
1331 | { |
---|
1332 | fclose($v_zip_temp_fd); |
---|
1333 | $this->privCloseFd(); |
---|
1334 | @unlink($v_zip_temp_name); |
---|
1335 | $this->privSwapBackMagicQuotes(); |
---|
1336 | |
---|
1337 | return $v_result; |
---|
1338 | } |
---|
1339 | |
---|
1340 | $v_offset = @ftell($this->zip_fd); |
---|
1341 | |
---|
1342 | $v_size = $v_central_dir['size']; |
---|
1343 | while ($v_size != 0) |
---|
1344 | { |
---|
1345 | $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
---|
1346 | $v_buffer = @fread($v_zip_temp_fd, $v_read_size); |
---|
1347 | @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
---|
1348 | $v_size -= $v_read_size; |
---|
1349 | } |
---|
1350 | |
---|
1351 | for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++) |
---|
1352 | { |
---|
1353 | if ($v_header_list[$i]['status'] == 'ok') { |
---|
1354 | if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
---|
1355 | fclose($v_zip_temp_fd); |
---|
1356 | $this->privCloseFd(); |
---|
1357 | @unlink($v_zip_temp_name); |
---|
1358 | $this->privSwapBackMagicQuotes(); |
---|
1359 | |
---|
1360 | return $v_result; |
---|
1361 | } |
---|
1362 | $v_count++; |
---|
1363 | } |
---|
1364 | |
---|
1365 | $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
---|
1366 | } |
---|
1367 | |
---|
1368 | $v_comment = $v_central_dir['comment']; |
---|
1369 | if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
---|
1370 | $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
---|
1371 | } |
---|
1372 | if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) { |
---|
1373 | $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT]; |
---|
1374 | } |
---|
1375 | if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) { |
---|
1376 | $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment; |
---|
1377 | } |
---|
1378 | |
---|
1379 | $v_size = @ftell($this->zip_fd)-$v_offset; |
---|
1380 | |
---|
1381 | if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) |
---|
1382 | { |
---|
1383 | unset($v_header_list); |
---|
1384 | $this->privSwapBackMagicQuotes(); |
---|
1385 | |
---|
1386 | return $v_result; |
---|
1387 | } |
---|
1388 | |
---|
1389 | $v_swap = $this->zip_fd; |
---|
1390 | $this->zip_fd = $v_zip_temp_fd; |
---|
1391 | $v_zip_temp_fd = $v_swap; |
---|
1392 | |
---|
1393 | $this->privCloseFd(); |
---|
1394 | |
---|
1395 | @fclose($v_zip_temp_fd); |
---|
1396 | |
---|
1397 | $this->privSwapBackMagicQuotes(); |
---|
1398 | |
---|
1399 | @unlink($this->zipname); |
---|
1400 | |
---|
1401 | PclZipUtilRename($v_zip_temp_name, $this->zipname); |
---|
1402 | |
---|
1403 | return $v_result; |
---|
1404 | } |
---|
1405 | |
---|
1406 | function privOpenFd($p_mode) |
---|
1407 | { |
---|
1408 | $v_result=1; |
---|
1409 | |
---|
1410 | if ($this->zip_fd != 0) |
---|
1411 | { |
---|
1412 | PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); |
---|
1413 | |
---|
1414 | return PclZip::errorCode(); |
---|
1415 | } |
---|
1416 | |
---|
1417 | if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) |
---|
1418 | { |
---|
1419 | PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); |
---|
1420 | |
---|
1421 | return PclZip::errorCode(); |
---|
1422 | } |
---|
1423 | |
---|
1424 | return $v_result; |
---|
1425 | } |
---|
1426 | |
---|
1427 | function privCloseFd() |
---|
1428 | { |
---|
1429 | $v_result=1; |
---|
1430 | |
---|
1431 | if ($this->zip_fd != 0) |
---|
1432 | @fclose($this->zip_fd); |
---|
1433 | $this->zip_fd = 0; |
---|
1434 | |
---|
1435 | return $v_result; |
---|
1436 | } |
---|
1437 | |
---|
1438 | function privAddList($p_filedescr_list, &$p_result_list, &$p_options) |
---|
1439 | { |
---|
1440 | $v_result=1; |
---|
1441 | |
---|
1442 | $v_header_list = array(); |
---|
1443 | if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) |
---|
1444 | { |
---|
1445 | return $v_result; |
---|
1446 | } |
---|
1447 | |
---|
1448 | $v_offset = @ftell($this->zip_fd); |
---|
1449 | |
---|
1450 | for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++) |
---|
1451 | { |
---|
1452 | if ($v_header_list[$i]['status'] == 'ok') { |
---|
1453 | if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
---|
1454 | return $v_result; |
---|
1455 | } |
---|
1456 | $v_count++; |
---|
1457 | } |
---|
1458 | |
---|
1459 | $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
---|
1460 | } |
---|
1461 | |
---|
1462 | $v_comment = ''; |
---|
1463 | if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
---|
1464 | $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
---|
1465 | } |
---|
1466 | |
---|
1467 | $v_size = @ftell($this->zip_fd)-$v_offset; |
---|
1468 | |
---|
1469 | if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) |
---|
1470 | { |
---|
1471 | unset($v_header_list); |
---|
1472 | |
---|
1473 | return $v_result; |
---|
1474 | } |
---|
1475 | |
---|
1476 | return $v_result; |
---|
1477 | } |
---|
1478 | |
---|
1479 | function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) |
---|
1480 | { |
---|
1481 | $v_result=1; |
---|
1482 | $v_header = array(); |
---|
1483 | |
---|
1484 | $v_nb = sizeof($p_result_list); |
---|
1485 | |
---|
1486 | for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { |
---|
1487 | $p_filedescr_list[$j]['filename'] |
---|
1488 | = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); |
---|
1489 | |
---|
1490 | |
---|
1491 | if ($p_filedescr_list[$j]['filename'] == "") { |
---|
1492 | continue; |
---|
1493 | } |
---|
1494 | |
---|
1495 | if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') |
---|
1496 | && (!file_exists($p_filedescr_list[$j]['filename']))) { |
---|
1497 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exists"); |
---|
1498 | return PclZip::errorCode(); |
---|
1499 | } |
---|
1500 | |
---|
1501 | if ( ($p_filedescr_list[$j]['type'] == 'file') |
---|
1502 | || ($p_filedescr_list[$j]['type'] == 'virtual_file') |
---|
1503 | || ( ($p_filedescr_list[$j]['type'] == 'folder') |
---|
1504 | && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) |
---|
1505 | || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
---|
1506 | ) { |
---|
1507 | |
---|
1508 | $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header, |
---|
1509 | $p_options); |
---|
1510 | if ($v_result != 1) { |
---|
1511 | return $v_result; |
---|
1512 | } |
---|
1513 | |
---|
1514 | $p_result_list[$v_nb++] = $v_header; |
---|
1515 | } |
---|
1516 | } |
---|
1517 | |
---|
1518 | return $v_result; |
---|
1519 | } |
---|
1520 | |
---|
1521 | function privAddFile($p_filedescr, &$p_header, &$p_options) |
---|
1522 | { |
---|
1523 | $v_result=1; |
---|
1524 | |
---|
1525 | $p_filename = $p_filedescr['filename']; |
---|
1526 | |
---|
1527 | if ($p_filename == "") { |
---|
1528 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); |
---|
1529 | |
---|
1530 | return PclZip::errorCode(); |
---|
1531 | } |
---|
1532 | |
---|
1533 | |
---|
1534 | |
---|
1535 | clearstatcache(); |
---|
1536 | $p_header['version'] = 20; |
---|
1537 | $p_header['version_extracted'] = 10; |
---|
1538 | $p_header['flag'] = 0; |
---|
1539 | $p_header['compression'] = 0; |
---|
1540 | $p_header['crc'] = 0; |
---|
1541 | $p_header['compressed_size'] = 0; |
---|
1542 | $p_header['filename_len'] = strlen($p_filename); |
---|
1543 | $p_header['extra_len'] = 0; |
---|
1544 | $p_header['disk'] = 0; |
---|
1545 | $p_header['internal'] = 0; |
---|
1546 | $p_header['offset'] = 0; |
---|
1547 | $p_header['filename'] = $p_filename; |
---|
1548 | $p_header['stored_filename'] = $p_filedescr['stored_filename']; |
---|
1549 | $p_header['extra'] = ''; |
---|
1550 | $p_header['status'] = 'ok'; |
---|
1551 | $p_header['index'] = -1; |
---|
1552 | |
---|
1553 | if ($p_filedescr['type']=='file') { |
---|
1554 | $p_header['external'] = 0x00000000; |
---|
1555 | $p_header['size'] = filesize($p_filename); |
---|
1556 | } |
---|
1557 | |
---|
1558 | else if ($p_filedescr['type']=='folder') { |
---|
1559 | $p_header['external'] = 0x00000010; |
---|
1560 | $p_header['mtime'] = filemtime($p_filename); |
---|
1561 | $p_header['size'] = filesize($p_filename); |
---|
1562 | } |
---|
1563 | |
---|
1564 | else if ($p_filedescr['type'] == 'virtual_file') { |
---|
1565 | $p_header['external'] = 0x00000000; |
---|
1566 | $p_header['size'] = strlen($p_filedescr['content']); |
---|
1567 | } |
---|
1568 | |
---|
1569 | |
---|
1570 | if (isset($p_filedescr['mtime'])) { |
---|
1571 | $p_header['mtime'] = $p_filedescr['mtime']; |
---|
1572 | } |
---|
1573 | else if ($p_filedescr['type'] == 'virtual_file') { |
---|
1574 | $p_header['mtime'] = mktime(); |
---|
1575 | } |
---|
1576 | else { |
---|
1577 | $p_header['mtime'] = filemtime($p_filename); |
---|
1578 | } |
---|
1579 | |
---|
1580 | if (isset($p_filedescr['comment'])) { |
---|
1581 | $p_header['comment_len'] = strlen($p_filedescr['comment']); |
---|
1582 | $p_header['comment'] = $p_filedescr['comment']; |
---|
1583 | } |
---|
1584 | else { |
---|
1585 | $p_header['comment_len'] = 0; |
---|
1586 | $p_header['comment'] = ''; |
---|
1587 | } |
---|
1588 | |
---|
1589 | if (isset($p_options[PCLZIP_CB_PRE_ADD])) { |
---|
1590 | |
---|
1591 | $v_local_header = array(); |
---|
1592 | $this->privConvertHeader2FileInfo($p_header, $v_local_header); |
---|
1593 | |
---|
1594 | eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);'); |
---|
1595 | if ($v_result == 0) { |
---|
1596 | $p_header['status'] = "skipped"; |
---|
1597 | $v_result = 1; |
---|
1598 | } |
---|
1599 | |
---|
1600 | if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { |
---|
1601 | $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); |
---|
1602 | } |
---|
1603 | } |
---|
1604 | |
---|
1605 | if ($p_header['stored_filename'] == "") { |
---|
1606 | $p_header['status'] = "filtered"; |
---|
1607 | } |
---|
1608 | |
---|
1609 | if (strlen($p_header['stored_filename']) > 0xFF) { |
---|
1610 | $p_header['status'] = 'filename_too_long'; |
---|
1611 | } |
---|
1612 | |
---|
1613 | if ($p_header['status'] == 'ok') { |
---|
1614 | |
---|
1615 | if ( ($p_filedescr['type'] == 'file') |
---|
1616 | || ($p_filedescr['type'] == 'virtual_file')) { |
---|
1617 | |
---|
1618 | if ($p_filedescr['type'] == 'file') { |
---|
1619 | |
---|
1620 | if (($v_file = @fopen($p_filename, "rb")) == 0) { |
---|
1621 | PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
---|
1622 | return PclZip::errorCode(); |
---|
1623 | } |
---|
1624 | |
---|
1625 | $v_content = @fread($v_file, $p_header['size']); |
---|
1626 | |
---|
1627 | @fclose($v_file); |
---|
1628 | } |
---|
1629 | else if ($p_filedescr['type'] == 'virtual_file') { |
---|
1630 | $v_content = $p_filedescr['content']; |
---|
1631 | } |
---|
1632 | |
---|
1633 | $p_header['crc'] = @crc32($v_content); |
---|
1634 | |
---|
1635 | if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { |
---|
1636 | $p_header['compressed_size'] = $p_header['size']; |
---|
1637 | $p_header['compression'] = 0; |
---|
1638 | } |
---|
1639 | |
---|
1640 | else { |
---|
1641 | $v_content = @gzdeflate($v_content); |
---|
1642 | |
---|
1643 | $p_header['compressed_size'] = strlen($v_content); |
---|
1644 | $p_header['compression'] = 8; |
---|
1645 | } |
---|
1646 | |
---|
1647 | |
---|
1648 | |
---|
1649 | if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
---|
1650 | @fclose($v_file); |
---|
1651 | return $v_result; |
---|
1652 | } |
---|
1653 | |
---|
1654 | @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); |
---|
1655 | } |
---|
1656 | |
---|
1657 | else if ($p_filedescr['type'] == 'folder') { |
---|
1658 | if (@substr($p_header['stored_filename'], -1) != '/') { |
---|
1659 | $p_header['stored_filename'] .= '/'; |
---|
1660 | } |
---|
1661 | |
---|
1662 | $p_header['size'] = 0; |
---|
1663 | $p_header['external'] = 0x00000010; |
---|
1664 | if (($v_result = $this->privWriteFileHeader($p_header)) != 1) |
---|
1665 | { |
---|
1666 | return $v_result; |
---|
1667 | } |
---|
1668 | } |
---|
1669 | } |
---|
1670 | |
---|
1671 | if (isset($p_options[PCLZIP_CB_POST_ADD])) { |
---|
1672 | |
---|
1673 | $v_local_header = array(); |
---|
1674 | $this->privConvertHeader2FileInfo($p_header, $v_local_header); |
---|
1675 | |
---|
1676 | eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);'); |
---|
1677 | if ($v_result == 0) { |
---|
1678 | $v_result = 1; |
---|
1679 | } |
---|
1680 | |
---|
1681 | } |
---|
1682 | |
---|
1683 | return $v_result; |
---|
1684 | } |
---|
1685 | |
---|
1686 | function privCalculateStoredFilename(&$p_filedescr, &$p_options) |
---|
1687 | { |
---|
1688 | $v_result=1; |
---|
1689 | |
---|
1690 | $p_filename = $p_filedescr['filename']; |
---|
1691 | if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { |
---|
1692 | $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; |
---|
1693 | } |
---|
1694 | else { |
---|
1695 | $p_add_dir = ''; |
---|
1696 | } |
---|
1697 | if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { |
---|
1698 | $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; |
---|
1699 | } |
---|
1700 | else { |
---|
1701 | $p_remove_dir = ''; |
---|
1702 | } |
---|
1703 | if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
---|
1704 | $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
---|
1705 | } |
---|
1706 | else { |
---|
1707 | $p_remove_all_dir = 0; |
---|
1708 | } |
---|
1709 | |
---|
1710 | if (isset($p_filedescr['new_full_name'])) { |
---|
1711 | $v_stored_filename = $p_filedescr['new_full_name']; |
---|
1712 | } |
---|
1713 | |
---|
1714 | else { |
---|
1715 | |
---|
1716 | if (isset($p_filedescr['new_short_name'])) { |
---|
1717 | $v_path_info = pathinfo($p_filename); |
---|
1718 | $v_dir = ''; |
---|
1719 | if ($v_path_info['dirname'] != '') { |
---|
1720 | $v_dir = $v_path_info['dirname'].'/'; |
---|
1721 | } |
---|
1722 | $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; |
---|
1723 | } |
---|
1724 | else { |
---|
1725 | $v_stored_filename = $p_filename; |
---|
1726 | } |
---|
1727 | |
---|
1728 | if ($p_remove_all_dir) { |
---|
1729 | $v_stored_filename = basename($p_filename); |
---|
1730 | } |
---|
1731 | else if ($p_remove_dir != "") { |
---|
1732 | if (substr($p_remove_dir, -1) != '/') |
---|
1733 | $p_remove_dir .= "/"; |
---|
1734 | |
---|
1735 | if ( (substr($p_filename, 0, 2) == "./") |
---|
1736 | || (substr($p_remove_dir, 0, 2) == "./")) { |
---|
1737 | |
---|
1738 | if ( (substr($p_filename, 0, 2) == "./") |
---|
1739 | && (substr($p_remove_dir, 0, 2) != "./")) { |
---|
1740 | $p_remove_dir = "./".$p_remove_dir; |
---|
1741 | } |
---|
1742 | if ( (substr($p_filename, 0, 2) != "./") |
---|
1743 | && (substr($p_remove_dir, 0, 2) == "./")) { |
---|
1744 | $p_remove_dir = substr($p_remove_dir, 2); |
---|
1745 | } |
---|
1746 | } |
---|
1747 | |
---|
1748 | $v_compare = PclZipUtilPathInclusion($p_remove_dir, |
---|
1749 | $v_stored_filename); |
---|
1750 | if ($v_compare > 0) { |
---|
1751 | if ($v_compare == 2) { |
---|
1752 | $v_stored_filename = ""; |
---|
1753 | } |
---|
1754 | else { |
---|
1755 | $v_stored_filename = substr($v_stored_filename, |
---|
1756 | strlen($p_remove_dir)); |
---|
1757 | } |
---|
1758 | } |
---|
1759 | } |
---|
1760 | if ($p_add_dir != "") { |
---|
1761 | if (substr($p_add_dir, -1) == "/") |
---|
1762 | $v_stored_filename = $p_add_dir.$v_stored_filename; |
---|
1763 | else |
---|
1764 | $v_stored_filename = $p_add_dir."/".$v_stored_filename; |
---|
1765 | } |
---|
1766 | } |
---|
1767 | |
---|
1768 | $v_stored_filename = PclZipUtilPathReduction($v_stored_filename); |
---|
1769 | $p_filedescr['stored_filename'] = $v_stored_filename; |
---|
1770 | |
---|
1771 | return $v_result; |
---|
1772 | } |
---|
1773 | |
---|
1774 | function privWriteFileHeader(&$p_header) |
---|
1775 | { |
---|
1776 | $v_result=1; |
---|
1777 | |
---|
1778 | $p_header['offset'] = ftell($this->zip_fd); |
---|
1779 | |
---|
1780 | $v_date = getdate($p_header['mtime']); |
---|
1781 | $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; |
---|
1782 | $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; |
---|
1783 | |
---|
1784 | $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, |
---|
1785 | $p_header['version_extracted'], $p_header['flag'], |
---|
1786 | $p_header['compression'], $v_mtime, $v_mdate, |
---|
1787 | $p_header['crc'], $p_header['compressed_size'], |
---|
1788 | $p_header['size'], |
---|
1789 | strlen($p_header['stored_filename']), |
---|
1790 | $p_header['extra_len']); |
---|
1791 | |
---|
1792 | fputs($this->zip_fd, $v_binary_data, 30); |
---|
1793 | |
---|
1794 | if (strlen($p_header['stored_filename']) != 0) |
---|
1795 | { |
---|
1796 | fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); |
---|
1797 | } |
---|
1798 | if ($p_header['extra_len'] != 0) |
---|
1799 | { |
---|
1800 | fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); |
---|
1801 | } |
---|
1802 | |
---|
1803 | return $v_result; |
---|
1804 | } |
---|
1805 | |
---|
1806 | function privWriteCentralFileHeader(&$p_header) |
---|
1807 | { |
---|
1808 | $v_result=1; |
---|
1809 | |
---|
1810 | |
---|
1811 | $v_date = getdate($p_header['mtime']); |
---|
1812 | $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; |
---|
1813 | $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; |
---|
1814 | |
---|
1815 | |
---|
1816 | $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, |
---|
1817 | $p_header['version'], $p_header['version_extracted'], |
---|
1818 | $p_header['flag'], $p_header['compression'], |
---|
1819 | $v_mtime, $v_mdate, $p_header['crc'], |
---|
1820 | $p_header['compressed_size'], $p_header['size'], |
---|
1821 | strlen($p_header['stored_filename']), |
---|
1822 | $p_header['extra_len'], $p_header['comment_len'], |
---|
1823 | $p_header['disk'], $p_header['internal'], |
---|
1824 | $p_header['external'], $p_header['offset']); |
---|
1825 | |
---|
1826 | fputs($this->zip_fd, $v_binary_data, 46); |
---|
1827 | |
---|
1828 | if (strlen($p_header['stored_filename']) != 0) |
---|
1829 | { |
---|
1830 | fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); |
---|
1831 | } |
---|
1832 | if ($p_header['extra_len'] != 0) |
---|
1833 | { |
---|
1834 | fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); |
---|
1835 | } |
---|
1836 | if ($p_header['comment_len'] != 0) |
---|
1837 | { |
---|
1838 | fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']); |
---|
1839 | } |
---|
1840 | |
---|
1841 | return $v_result; |
---|
1842 | } |
---|
1843 | |
---|
1844 | function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) |
---|
1845 | { |
---|
1846 | $v_result=1; |
---|
1847 | |
---|
1848 | $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, |
---|
1849 | $p_nb_entries, $p_size, |
---|
1850 | $p_offset, strlen($p_comment)); |
---|
1851 | |
---|
1852 | fputs($this->zip_fd, $v_binary_data, 22); |
---|
1853 | |
---|
1854 | if (strlen($p_comment) != 0) |
---|
1855 | { |
---|
1856 | fputs($this->zip_fd, $p_comment, strlen($p_comment)); |
---|
1857 | } |
---|
1858 | |
---|
1859 | return $v_result; |
---|
1860 | } |
---|
1861 | |
---|
1862 | function privList(&$p_list) |
---|
1863 | { |
---|
1864 | $v_result=1; |
---|
1865 | |
---|
1866 | $this->privDisableMagicQuotes(); |
---|
1867 | |
---|
1868 | if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) |
---|
1869 | { |
---|
1870 | $this->privSwapBackMagicQuotes(); |
---|
1871 | |
---|
1872 | PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
---|
1873 | |
---|
1874 | return PclZip::errorCode(); |
---|
1875 | } |
---|
1876 | |
---|
1877 | $v_central_dir = array(); |
---|
1878 | if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
---|
1879 | { |
---|
1880 | $this->privSwapBackMagicQuotes(); |
---|
1881 | return $v_result; |
---|
1882 | } |
---|
1883 | |
---|
1884 | @rewind($this->zip_fd); |
---|
1885 | if (@fseek($this->zip_fd, $v_central_dir['offset'])) |
---|
1886 | { |
---|
1887 | $this->privSwapBackMagicQuotes(); |
---|
1888 | |
---|
1889 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
---|
1890 | |
---|
1891 | return PclZip::errorCode(); |
---|
1892 | } |
---|
1893 | |
---|
1894 | for ($i=0; $i<$v_central_dir['entries']; $i++) |
---|
1895 | { |
---|
1896 | if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
---|
1897 | { |
---|
1898 | $this->privSwapBackMagicQuotes(); |
---|
1899 | return $v_result; |
---|
1900 | } |
---|
1901 | $v_header['index'] = $i; |
---|
1902 | |
---|
1903 | $this->privConvertHeader2FileInfo($v_header, $p_list[$i]); |
---|
1904 | unset($v_header); |
---|
1905 | } |
---|
1906 | |
---|
1907 | $this->privCloseFd(); |
---|
1908 | |
---|
1909 | $this->privSwapBackMagicQuotes(); |
---|
1910 | |
---|
1911 | return $v_result; |
---|
1912 | } |
---|
1913 | |
---|
1914 | function privConvertHeader2FileInfo($p_header, &$p_info) |
---|
1915 | { |
---|
1916 | $v_result=1; |
---|
1917 | |
---|
1918 | $p_info['filename'] = $p_header['filename']; |
---|
1919 | $p_info['stored_filename'] = $p_header['stored_filename']; |
---|
1920 | $p_info['size'] = $p_header['size']; |
---|
1921 | $p_info['compressed_size'] = $p_header['compressed_size']; |
---|
1922 | $p_info['mtime'] = $p_header['mtime']; |
---|
1923 | $p_info['comment'] = $p_header['comment']; |
---|
1924 | $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); |
---|
1925 | $p_info['index'] = $p_header['index']; |
---|
1926 | $p_info['status'] = $p_header['status']; |
---|
1927 | $p_info['crc'] = $p_header['crc']; |
---|
1928 | |
---|
1929 | return $v_result; |
---|
1930 | } |
---|
1931 | |
---|
1932 | function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
---|
1933 | { |
---|
1934 | $v_result=1; |
---|
1935 | |
---|
1936 | $this->privDisableMagicQuotes(); |
---|
1937 | |
---|
1938 | if ( ($p_path == "") |
---|
1939 | || ( (substr($p_path, 0, 1) != "/") |
---|
1940 | && (substr($p_path, 0, 3) != "../") |
---|
1941 | && (substr($p_path,1,2)!=":/"))) |
---|
1942 | $p_path = "./".$p_path; |
---|
1943 | |
---|
1944 | if (($p_path != "./") && ($p_path != "/")) |
---|
1945 | { |
---|
1946 | while (substr($p_path, -1) == "/") |
---|
1947 | { |
---|
1948 | $p_path = substr($p_path, 0, strlen($p_path)-1); |
---|
1949 | } |
---|
1950 | } |
---|
1951 | |
---|
1952 | if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/')) |
---|
1953 | { |
---|
1954 | $p_remove_path .= '/'; |
---|
1955 | } |
---|
1956 | $p_remove_path_size = strlen($p_remove_path); |
---|
1957 | |
---|
1958 | if (($v_result = $this->privOpenFd('rb')) != 1) |
---|
1959 | { |
---|
1960 | $this->privSwapBackMagicQuotes(); |
---|
1961 | return $v_result; |
---|
1962 | } |
---|
1963 | |
---|
1964 | $v_central_dir = array(); |
---|
1965 | if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
---|
1966 | { |
---|
1967 | $this->privCloseFd(); |
---|
1968 | $this->privSwapBackMagicQuotes(); |
---|
1969 | |
---|
1970 | return $v_result; |
---|
1971 | } |
---|
1972 | |
---|
1973 | $v_pos_entry = $v_central_dir['offset']; |
---|
1974 | |
---|
1975 | $j_start = 0; |
---|
1976 | for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
---|
1977 | { |
---|
1978 | |
---|
1979 | @rewind($this->zip_fd); |
---|
1980 | if (@fseek($this->zip_fd, $v_pos_entry)) |
---|
1981 | { |
---|
1982 | $this->privCloseFd(); |
---|
1983 | $this->privSwapBackMagicQuotes(); |
---|
1984 | |
---|
1985 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
---|
1986 | |
---|
1987 | return PclZip::errorCode(); |
---|
1988 | } |
---|
1989 | |
---|
1990 | $v_header = array(); |
---|
1991 | if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
---|
1992 | { |
---|
1993 | $this->privCloseFd(); |
---|
1994 | $this->privSwapBackMagicQuotes(); |
---|
1995 | |
---|
1996 | return $v_result; |
---|
1997 | } |
---|
1998 | |
---|
1999 | $v_header['index'] = $i; |
---|
2000 | |
---|
2001 | $v_pos_entry = ftell($this->zip_fd); |
---|
2002 | |
---|
2003 | $v_extract = false; |
---|
2004 | |
---|
2005 | if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
---|
2006 | && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
---|
2007 | |
---|
2008 | for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { |
---|
2009 | |
---|
2010 | if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
---|
2011 | |
---|
2012 | if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
---|
2013 | && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
---|
2014 | $v_extract = true; |
---|
2015 | } |
---|
2016 | } |
---|
2017 | elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
---|
2018 | $v_extract = true; |
---|
2019 | } |
---|
2020 | } |
---|
2021 | } |
---|
2022 | |
---|
2023 | else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) |
---|
2024 | && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { |
---|
2025 | |
---|
2026 | if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) { |
---|
2027 | $v_extract = true; |
---|
2028 | } |
---|
2029 | } |
---|
2030 | |
---|
2031 | else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
---|
2032 | && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
---|
2033 | |
---|
2034 | if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { |
---|
2035 | $v_extract = true; |
---|
2036 | } |
---|
2037 | } |
---|
2038 | |
---|
2039 | else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
---|
2040 | && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
---|
2041 | |
---|
2042 | for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { |
---|
2043 | |
---|
2044 | if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
---|
2045 | $v_extract = true; |
---|
2046 | } |
---|
2047 | if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
---|
2048 | $j_start = $j+1; |
---|
2049 | } |
---|
2050 | |
---|
2051 | if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
---|
2052 | break; |
---|
2053 | } |
---|
2054 | } |
---|
2055 | } |
---|
2056 | |
---|
2057 | else { |
---|
2058 | $v_extract = true; |
---|
2059 | } |
---|
2060 | |
---|
2061 | if ( ($v_extract) |
---|
2062 | && ( ($v_header['compression'] != 8) |
---|
2063 | && ($v_header['compression'] != 0))) { |
---|
2064 | $v_header['status'] = 'unsupported_compression'; |
---|
2065 | |
---|
2066 | if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
---|
2067 | && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
---|
2068 | |
---|
2069 | $this->privSwapBackMagicQuotes(); |
---|
2070 | |
---|
2071 | PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, |
---|
2072 | "Filename '".$v_header['stored_filename']."' is " |
---|
2073 | ."compressed by an unsupported compression " |
---|
2074 | ."method (".$v_header['compression'].") "); |
---|
2075 | |
---|
2076 | return PclZip::errorCode(); |
---|
2077 | } |
---|
2078 | } |
---|
2079 | |
---|
2080 | if (($v_extract) && (($v_header['flag'] & 1) == 1)) { |
---|
2081 | $v_header['status'] = 'unsupported_encryption'; |
---|
2082 | |
---|
2083 | if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
---|
2084 | && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
---|
2085 | |
---|
2086 | $this->privSwapBackMagicQuotes(); |
---|
2087 | |
---|
2088 | PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, |
---|
2089 | "Unsupported encryption for " |
---|
2090 | ." filename '".$v_header['stored_filename'] |
---|
2091 | ."'"); |
---|
2092 | |
---|
2093 | return PclZip::errorCode(); |
---|
2094 | } |
---|
2095 | } |
---|
2096 | |
---|
2097 | if (($v_extract) && ($v_header['status'] != 'ok')) { |
---|
2098 | $v_result = $this->privConvertHeader2FileInfo($v_header, |
---|
2099 | $p_file_list[$v_nb_extracted++]); |
---|
2100 | if ($v_result != 1) { |
---|
2101 | $this->privCloseFd(); |
---|
2102 | $this->privSwapBackMagicQuotes(); |
---|
2103 | return $v_result; |
---|
2104 | } |
---|
2105 | |
---|
2106 | $v_extract = false; |
---|
2107 | } |
---|
2108 | |
---|
2109 | if ($v_extract) |
---|
2110 | { |
---|
2111 | |
---|
2112 | @rewind($this->zip_fd); |
---|
2113 | if (@fseek($this->zip_fd, $v_header['offset'])) |
---|
2114 | { |
---|
2115 | $this->privCloseFd(); |
---|
2116 | |
---|
2117 | $this->privSwapBackMagicQuotes(); |
---|
2118 | |
---|
2119 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
---|
2120 | |
---|
2121 | return PclZip::errorCode(); |
---|
2122 | } |
---|
2123 | |
---|
2124 | if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) { |
---|
2125 | |
---|
2126 | $v_result1 = $this->privExtractFileAsString($v_header, $v_string); |
---|
2127 | if ($v_result1 < 1) { |
---|
2128 | $this->privCloseFd(); |
---|
2129 | $this->privSwapBackMagicQuotes(); |
---|
2130 | return $v_result1; |
---|
2131 | } |
---|
2132 | |
---|
2133 | if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) |
---|
2134 | { |
---|
2135 | $this->privCloseFd(); |
---|
2136 | $this->privSwapBackMagicQuotes(); |
---|
2137 | |
---|
2138 | return $v_result; |
---|
2139 | } |
---|
2140 | |
---|
2141 | $p_file_list[$v_nb_extracted]['content'] = $v_string; |
---|
2142 | |
---|
2143 | $v_nb_extracted++; |
---|
2144 | |
---|
2145 | if ($v_result1 == 2) { |
---|
2146 | break; |
---|
2147 | } |
---|
2148 | } |
---|
2149 | elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
---|
2150 | && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { |
---|
2151 | $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); |
---|
2152 | if ($v_result1 < 1) { |
---|
2153 | $this->privCloseFd(); |
---|
2154 | $this->privSwapBackMagicQuotes(); |
---|
2155 | return $v_result1; |
---|
2156 | } |
---|
2157 | |
---|
2158 | if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { |
---|
2159 | $this->privCloseFd(); |
---|
2160 | $this->privSwapBackMagicQuotes(); |
---|
2161 | return $v_result; |
---|
2162 | } |
---|
2163 | |
---|
2164 | if ($v_result1 == 2) { |
---|
2165 | break; |
---|
2166 | } |
---|
2167 | } |
---|
2168 | else { |
---|
2169 | $v_result1 = $this->privExtractFile($v_header, |
---|
2170 | $p_path, $p_remove_path, |
---|
2171 | $p_remove_all_path, |
---|
2172 | $p_options); |
---|
2173 | if ($v_result1 < 1) { |
---|
2174 | $this->privCloseFd(); |
---|
2175 | $this->privSwapBackMagicQuotes(); |
---|
2176 | return $v_result1; |
---|
2177 | } |
---|
2178 | |
---|
2179 | if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) |
---|
2180 | { |
---|
2181 | $this->privCloseFd(); |
---|
2182 | $this->privSwapBackMagicQuotes(); |
---|
2183 | |
---|
2184 | return $v_result; |
---|
2185 | } |
---|
2186 | |
---|
2187 | if ($v_result1 == 2) { |
---|
2188 | break; |
---|
2189 | } |
---|
2190 | } |
---|
2191 | } |
---|
2192 | } |
---|
2193 | |
---|
2194 | $this->privCloseFd(); |
---|
2195 | $this->privSwapBackMagicQuotes(); |
---|
2196 | |
---|
2197 | return $v_result; |
---|
2198 | } |
---|
2199 | |
---|
2200 | function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
---|
2201 | { |
---|
2202 | $v_result=1; |
---|
2203 | |
---|
2204 | if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
---|
2205 | { |
---|
2206 | return $v_result; |
---|
2207 | } |
---|
2208 | |
---|
2209 | |
---|
2210 | if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
---|
2211 | } |
---|
2212 | |
---|
2213 | if ($p_remove_all_path == true) { |
---|
2214 | if (($p_entry['external']&0x00000010)==0x00000010) { |
---|
2215 | |
---|
2216 | $p_entry['status'] = "filtered"; |
---|
2217 | |
---|
2218 | return $v_result; |
---|
2219 | } |
---|
2220 | |
---|
2221 | $p_entry['filename'] = basename($p_entry['filename']); |
---|
2222 | } |
---|
2223 | |
---|
2224 | else if ($p_remove_path != "") |
---|
2225 | { |
---|
2226 | if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) |
---|
2227 | { |
---|
2228 | |
---|
2229 | $p_entry['status'] = "filtered"; |
---|
2230 | |
---|
2231 | return $v_result; |
---|
2232 | } |
---|
2233 | |
---|
2234 | $p_remove_path_size = strlen($p_remove_path); |
---|
2235 | if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) |
---|
2236 | { |
---|
2237 | |
---|
2238 | $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); |
---|
2239 | |
---|
2240 | } |
---|
2241 | } |
---|
2242 | |
---|
2243 | if ($p_path != '') { |
---|
2244 | $p_entry['filename'] = $p_path."/".$p_entry['filename']; |
---|
2245 | } |
---|
2246 | |
---|
2247 | if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { |
---|
2248 | $v_inclusion |
---|
2249 | = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], |
---|
2250 | $p_entry['filename']); |
---|
2251 | if ($v_inclusion == 0) { |
---|
2252 | |
---|
2253 | PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, |
---|
2254 | "Filename '".$p_entry['filename']."' is " |
---|
2255 | ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); |
---|
2256 | |
---|
2257 | return PclZip::errorCode(); |
---|
2258 | } |
---|
2259 | } |
---|
2260 | |
---|
2261 | if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
---|
2262 | |
---|
2263 | $v_local_header = array(); |
---|
2264 | $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
---|
2265 | |
---|
2266 | eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); |
---|
2267 | if ($v_result == 0) { |
---|
2268 | $p_entry['status'] = "skipped"; |
---|
2269 | $v_result = 1; |
---|
2270 | } |
---|
2271 | |
---|
2272 | if ($v_result == 2) { |
---|
2273 | $p_entry['status'] = "aborted"; |
---|
2274 | $v_result = PCLZIP_ERR_USER_ABORTED; |
---|
2275 | } |
---|
2276 | |
---|
2277 | $p_entry['filename'] = $v_local_header['filename']; |
---|
2278 | } |
---|
2279 | |
---|
2280 | |
---|
2281 | if ($p_entry['status'] == 'ok') { |
---|
2282 | |
---|
2283 | if (file_exists($p_entry['filename'])) |
---|
2284 | { |
---|
2285 | |
---|
2286 | if (is_dir($p_entry['filename'])) |
---|
2287 | { |
---|
2288 | |
---|
2289 | $p_entry['status'] = "already_a_directory"; |
---|
2290 | |
---|
2291 | if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
---|
2292 | && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
---|
2293 | |
---|
2294 | PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, |
---|
2295 | "Filename '".$p_entry['filename']."' is " |
---|
2296 | ."already used by an existing directory"); |
---|
2297 | |
---|
2298 | return PclZip::errorCode(); |
---|
2299 | } |
---|
2300 | } |
---|
2301 | else if (!is_writeable($p_entry['filename'])) |
---|
2302 | { |
---|
2303 | |
---|
2304 | $p_entry['status'] = "write_protected"; |
---|
2305 | |
---|
2306 | if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
---|
2307 | && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
---|
2308 | |
---|
2309 | PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
---|
2310 | "Filename '".$p_entry['filename']."' exists " |
---|
2311 | ."and is write protected"); |
---|
2312 | |
---|
2313 | return PclZip::errorCode(); |
---|
2314 | } |
---|
2315 | } |
---|
2316 | |
---|
2317 | else if (filemtime($p_entry['filename']) > $p_entry['mtime']) |
---|
2318 | { |
---|
2319 | if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) |
---|
2320 | && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { |
---|
2321 | } |
---|
2322 | else { |
---|
2323 | $p_entry['status'] = "newer_exist"; |
---|
2324 | |
---|
2325 | if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
---|
2326 | && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
---|
2327 | |
---|
2328 | PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
---|
2329 | "Newer version of '".$p_entry['filename']."' exists " |
---|
2330 | ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); |
---|
2331 | |
---|
2332 | return PclZip::errorCode(); |
---|
2333 | } |
---|
2334 | } |
---|
2335 | } |
---|
2336 | else { |
---|
2337 | } |
---|
2338 | } |
---|
2339 | |
---|
2340 | else { |
---|
2341 | if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) |
---|
2342 | $v_dir_to_check = $p_entry['filename']; |
---|
2343 | else if (!strstr($p_entry['filename'], "/")) |
---|
2344 | $v_dir_to_check = ""; |
---|
2345 | else |
---|
2346 | $v_dir_to_check = dirname($p_entry['filename']); |
---|
2347 | |
---|
2348 | if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { |
---|
2349 | |
---|
2350 | $p_entry['status'] = "path_creation_fail"; |
---|
2351 | |
---|
2352 | $v_result = 1; |
---|
2353 | } |
---|
2354 | } |
---|
2355 | } |
---|
2356 | |
---|
2357 | if ($p_entry['status'] == 'ok') { |
---|
2358 | |
---|
2359 | if (!(($p_entry['external']&0x00000010)==0x00000010)) |
---|
2360 | { |
---|
2361 | if ($p_entry['compression'] == 0) { |
---|
2362 | |
---|
2363 | if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) |
---|
2364 | { |
---|
2365 | |
---|
2366 | $p_entry['status'] = "write_error"; |
---|
2367 | |
---|
2368 | return $v_result; |
---|
2369 | } |
---|
2370 | |
---|
2371 | |
---|
2372 | $v_size = $p_entry['compressed_size']; |
---|
2373 | while ($v_size != 0) |
---|
2374 | { |
---|
2375 | $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
---|
2376 | $v_buffer = @fread($this->zip_fd, $v_read_size); |
---|
2377 | |
---|
2378 | @fwrite($v_dest_file, $v_buffer, $v_read_size); |
---|
2379 | $v_size -= $v_read_size; |
---|
2380 | } |
---|
2381 | |
---|
2382 | fclose($v_dest_file); |
---|
2383 | |
---|
2384 | touch($p_entry['filename'], $p_entry['mtime']); |
---|
2385 | |
---|
2386 | |
---|
2387 | } |
---|
2388 | else { |
---|
2389 | if (($p_entry['flag'] & 1) == 1) { |
---|
2390 | |
---|
2391 | } |
---|
2392 | else { |
---|
2393 | $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
---|
2394 | } |
---|
2395 | |
---|
2396 | $v_file_content = @gzinflate($v_buffer); |
---|
2397 | unset($v_buffer); |
---|
2398 | if ($v_file_content === FALSE) { |
---|
2399 | |
---|
2400 | $p_entry['status'] = "error"; |
---|
2401 | |
---|
2402 | return $v_result; |
---|
2403 | } |
---|
2404 | |
---|
2405 | if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { |
---|
2406 | |
---|
2407 | $p_entry['status'] = "write_error"; |
---|
2408 | |
---|
2409 | return $v_result; |
---|
2410 | } |
---|
2411 | |
---|
2412 | @fwrite($v_dest_file, $v_file_content, $p_entry['size']); |
---|
2413 | unset($v_file_content); |
---|
2414 | |
---|
2415 | @fclose($v_dest_file); |
---|
2416 | |
---|
2417 | @touch($p_entry['filename'], $p_entry['mtime']); |
---|
2418 | } |
---|
2419 | |
---|
2420 | if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { |
---|
2421 | |
---|
2422 | @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); |
---|
2423 | } |
---|
2424 | |
---|
2425 | } |
---|
2426 | } |
---|
2427 | |
---|
2428 | if ($p_entry['status'] == "aborted") { |
---|
2429 | $p_entry['status'] = "skipped"; |
---|
2430 | } |
---|
2431 | |
---|
2432 | elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
---|
2433 | |
---|
2434 | $v_local_header = array(); |
---|
2435 | $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
---|
2436 | |
---|
2437 | eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); |
---|
2438 | |
---|
2439 | if ($v_result == 2) { |
---|
2440 | $v_result = PCLZIP_ERR_USER_ABORTED; |
---|
2441 | } |
---|
2442 | } |
---|
2443 | |
---|
2444 | return $v_result; |
---|
2445 | } |
---|
2446 | |
---|
2447 | function privExtractFileInOutput(&$p_entry, &$p_options) |
---|
2448 | { |
---|
2449 | $v_result=1; |
---|
2450 | |
---|
2451 | if (($v_result = $this->privReadFileHeader($v_header)) != 1) { |
---|
2452 | return $v_result; |
---|
2453 | } |
---|
2454 | |
---|
2455 | |
---|
2456 | if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
---|
2457 | } |
---|
2458 | |
---|
2459 | if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
---|
2460 | |
---|
2461 | $v_local_header = array(); |
---|
2462 | $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
---|
2463 | |
---|
2464 | eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); |
---|
2465 | if ($v_result == 0) { |
---|
2466 | $p_entry['status'] = "skipped"; |
---|
2467 | $v_result = 1; |
---|
2468 | } |
---|
2469 | |
---|
2470 | if ($v_result == 2) { |
---|
2471 | $p_entry['status'] = "aborted"; |
---|
2472 | $v_result = PCLZIP_ERR_USER_ABORTED; |
---|
2473 | } |
---|
2474 | |
---|
2475 | $p_entry['filename'] = $v_local_header['filename']; |
---|
2476 | } |
---|
2477 | |
---|
2478 | |
---|
2479 | if ($p_entry['status'] == 'ok') { |
---|
2480 | |
---|
2481 | if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
---|
2482 | if ($p_entry['compressed_size'] == $p_entry['size']) { |
---|
2483 | |
---|
2484 | $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
---|
2485 | |
---|
2486 | echo $v_buffer; |
---|
2487 | unset($v_buffer); |
---|
2488 | } |
---|
2489 | else { |
---|
2490 | |
---|
2491 | $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
---|
2492 | |
---|
2493 | $v_file_content = gzinflate($v_buffer); |
---|
2494 | unset($v_buffer); |
---|
2495 | |
---|
2496 | echo $v_file_content; |
---|
2497 | unset($v_file_content); |
---|
2498 | } |
---|
2499 | } |
---|
2500 | } |
---|
2501 | |
---|
2502 | if ($p_entry['status'] == "aborted") { |
---|
2503 | $p_entry['status'] = "skipped"; |
---|
2504 | } |
---|
2505 | |
---|
2506 | elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
---|
2507 | |
---|
2508 | $v_local_header = array(); |
---|
2509 | $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
---|
2510 | |
---|
2511 | eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); |
---|
2512 | |
---|
2513 | if ($v_result == 2) { |
---|
2514 | $v_result = PCLZIP_ERR_USER_ABORTED; |
---|
2515 | } |
---|
2516 | } |
---|
2517 | |
---|
2518 | return $v_result; |
---|
2519 | } |
---|
2520 | |
---|
2521 | function privExtractFileAsString(&$p_entry, &$p_string) |
---|
2522 | { |
---|
2523 | $v_result=1; |
---|
2524 | |
---|
2525 | $v_header = array(); |
---|
2526 | if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
---|
2527 | { |
---|
2528 | return $v_result; |
---|
2529 | } |
---|
2530 | |
---|
2531 | |
---|
2532 | if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) { |
---|
2533 | } |
---|
2534 | |
---|
2535 | |
---|
2536 | if (!(($p_entry['external']&0x00000010)==0x00000010)) |
---|
2537 | { |
---|
2538 | if ($p_entry['compression'] == 0) { |
---|
2539 | |
---|
2540 | $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); |
---|
2541 | } |
---|
2542 | else { |
---|
2543 | |
---|
2544 | $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); |
---|
2545 | |
---|
2546 | if (($p_string = @gzinflate($v_data)) === FALSE) { |
---|
2547 | } |
---|
2548 | } |
---|
2549 | |
---|
2550 | } |
---|
2551 | else { |
---|
2552 | } |
---|
2553 | |
---|
2554 | return $v_result; |
---|
2555 | } |
---|
2556 | |
---|
2557 | function privReadFileHeader(&$p_header) |
---|
2558 | { |
---|
2559 | $v_result=1; |
---|
2560 | |
---|
2561 | $v_binary_data = @fread($this->zip_fd, 4); |
---|
2562 | $v_data = unpack('Vid', $v_binary_data); |
---|
2563 | |
---|
2564 | if ($v_data['id'] != 0x04034b50) |
---|
2565 | { |
---|
2566 | |
---|
2567 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); |
---|
2568 | |
---|
2569 | return PclZip::errorCode(); |
---|
2570 | } |
---|
2571 | |
---|
2572 | $v_binary_data = fread($this->zip_fd, 26); |
---|
2573 | |
---|
2574 | if (strlen($v_binary_data) != 26) |
---|
2575 | { |
---|
2576 | $p_header['filename'] = ""; |
---|
2577 | $p_header['status'] = "invalid_header"; |
---|
2578 | |
---|
2579 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
---|
2580 | |
---|
2581 | return PclZip::errorCode(); |
---|
2582 | } |
---|
2583 | |
---|
2584 | $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data); |
---|
2585 | |
---|
2586 | $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']); |
---|
2587 | |
---|
2588 | if ($v_data['extra_len'] != 0) { |
---|
2589 | $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); |
---|
2590 | } |
---|
2591 | else { |
---|
2592 | $p_header['extra'] = ''; |
---|
2593 | } |
---|
2594 | |
---|
2595 | $p_header['version_extracted'] = $v_data['version']; |
---|
2596 | $p_header['compression'] = $v_data['compression']; |
---|
2597 | $p_header['size'] = $v_data['size']; |
---|
2598 | $p_header['compressed_size'] = $v_data['compressed_size']; |
---|
2599 | $p_header['crc'] = $v_data['crc']; |
---|
2600 | $p_header['flag'] = $v_data['flag']; |
---|
2601 | $p_header['filename_len'] = $v_data['filename_len']; |
---|
2602 | |
---|
2603 | $p_header['mdate'] = $v_data['mdate']; |
---|
2604 | $p_header['mtime'] = $v_data['mtime']; |
---|
2605 | if ($p_header['mdate'] && $p_header['mtime']) |
---|
2606 | { |
---|
2607 | $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
---|
2608 | $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
---|
2609 | $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
---|
2610 | |
---|
2611 | $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
---|
2612 | $v_month = ($p_header['mdate'] & 0x01E0) >> 5; |
---|
2613 | $v_day = $p_header['mdate'] & 0x001F; |
---|
2614 | |
---|
2615 | $p_header['mtime'] = mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
---|
2616 | |
---|
2617 | } |
---|
2618 | else |
---|
2619 | { |
---|
2620 | $p_header['mtime'] = time(); |
---|
2621 | } |
---|
2622 | |
---|
2623 | |
---|
2624 | $p_header['stored_filename'] = $p_header['filename']; |
---|
2625 | |
---|
2626 | $p_header['status'] = "ok"; |
---|
2627 | |
---|
2628 | return $v_result; |
---|
2629 | } |
---|
2630 | |
---|
2631 | function privReadCentralFileHeader(&$p_header) |
---|
2632 | { |
---|
2633 | $v_result=1; |
---|
2634 | |
---|
2635 | $v_binary_data = @fread($this->zip_fd, 4); |
---|
2636 | $v_data = unpack('Vid', $v_binary_data); |
---|
2637 | |
---|
2638 | if ($v_data['id'] != 0x02014b50) |
---|
2639 | { |
---|
2640 | |
---|
2641 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); |
---|
2642 | |
---|
2643 | return PclZip::errorCode(); |
---|
2644 | } |
---|
2645 | |
---|
2646 | $v_binary_data = fread($this->zip_fd, 42); |
---|
2647 | |
---|
2648 | if (strlen($v_binary_data) != 42) |
---|
2649 | { |
---|
2650 | $p_header['filename'] = ""; |
---|
2651 | $p_header['status'] = "invalid_header"; |
---|
2652 | |
---|
2653 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
---|
2654 | |
---|
2655 | return PclZip::errorCode(); |
---|
2656 | } |
---|
2657 | |
---|
2658 | $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data); |
---|
2659 | |
---|
2660 | if ($p_header['filename_len'] != 0) |
---|
2661 | $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); |
---|
2662 | else |
---|
2663 | $p_header['filename'] = ''; |
---|
2664 | |
---|
2665 | if ($p_header['extra_len'] != 0) |
---|
2666 | $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); |
---|
2667 | else |
---|
2668 | $p_header['extra'] = ''; |
---|
2669 | |
---|
2670 | if ($p_header['comment_len'] != 0) |
---|
2671 | $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); |
---|
2672 | else |
---|
2673 | $p_header['comment'] = ''; |
---|
2674 | |
---|
2675 | |
---|
2676 | if (1) |
---|
2677 | { |
---|
2678 | $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
---|
2679 | $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
---|
2680 | $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
---|
2681 | |
---|
2682 | $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
---|
2683 | $v_month = ($p_header['mdate'] & 0x01E0) >> 5; |
---|
2684 | $v_day = $p_header['mdate'] & 0x001F; |
---|
2685 | |
---|
2686 | $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
---|
2687 | |
---|
2688 | } |
---|
2689 | else |
---|
2690 | { |
---|
2691 | $p_header['mtime'] = time(); |
---|
2692 | } |
---|
2693 | |
---|
2694 | $p_header['stored_filename'] = $p_header['filename']; |
---|
2695 | |
---|
2696 | $p_header['status'] = 'ok'; |
---|
2697 | |
---|
2698 | if (substr($p_header['filename'], -1) == '/') { |
---|
2699 | $p_header['external'] = 0x00000010; |
---|
2700 | } |
---|
2701 | |
---|
2702 | |
---|
2703 | return $v_result; |
---|
2704 | } |
---|
2705 | |
---|
2706 | function privCheckFileHeaders(&$p_local_header, &$p_central_header) |
---|
2707 | { |
---|
2708 | $v_result=1; |
---|
2709 | |
---|
2710 | if ($p_local_header['filename'] != $p_central_header['filename']) { |
---|
2711 | } |
---|
2712 | if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { |
---|
2713 | } |
---|
2714 | if ($p_local_header['flag'] != $p_central_header['flag']) { |
---|
2715 | } |
---|
2716 | if ($p_local_header['compression'] != $p_central_header['compression']) { |
---|
2717 | } |
---|
2718 | if ($p_local_header['mtime'] != $p_central_header['mtime']) { |
---|
2719 | } |
---|
2720 | if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { |
---|
2721 | } |
---|
2722 | |
---|
2723 | if (($p_local_header['flag'] & 8) == 8) { |
---|
2724 | $p_local_header['size'] = $p_central_header['size']; |
---|
2725 | $p_local_header['compressed_size'] = $p_central_header['compressed_size']; |
---|
2726 | $p_local_header['crc'] = $p_central_header['crc']; |
---|
2727 | } |
---|
2728 | |
---|
2729 | return $v_result; |
---|
2730 | } |
---|
2731 | |
---|
2732 | function privReadEndCentralDir(&$p_central_dir) |
---|
2733 | { |
---|
2734 | $v_result=1; |
---|
2735 | |
---|
2736 | $v_size = filesize($this->zipname); |
---|
2737 | @fseek($this->zip_fd, $v_size); |
---|
2738 | if (@ftell($this->zip_fd) != $v_size) |
---|
2739 | { |
---|
2740 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); |
---|
2741 | |
---|
2742 | return PclZip::errorCode(); |
---|
2743 | } |
---|
2744 | |
---|
2745 | $v_found = 0; |
---|
2746 | if ($v_size > 26) { |
---|
2747 | @fseek($this->zip_fd, $v_size-22); |
---|
2748 | if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) |
---|
2749 | { |
---|
2750 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
---|
2751 | |
---|
2752 | return PclZip::errorCode(); |
---|
2753 | } |
---|
2754 | |
---|
2755 | $v_binary_data = @fread($this->zip_fd, 4); |
---|
2756 | $v_data = @unpack('Vid', $v_binary_data); |
---|
2757 | |
---|
2758 | if ($v_data['id'] == 0x06054b50) { |
---|
2759 | $v_found = 1; |
---|
2760 | } |
---|
2761 | |
---|
2762 | $v_pos = ftell($this->zip_fd); |
---|
2763 | } |
---|
2764 | |
---|
2765 | if (!$v_found) { |
---|
2766 | $v_maximum_size = 65557; if ($v_maximum_size > $v_size) |
---|
2767 | $v_maximum_size = $v_size; |
---|
2768 | @fseek($this->zip_fd, $v_size-$v_maximum_size); |
---|
2769 | if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) |
---|
2770 | { |
---|
2771 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
---|
2772 | |
---|
2773 | return PclZip::errorCode(); |
---|
2774 | } |
---|
2775 | |
---|
2776 | $v_pos = ftell($this->zip_fd); |
---|
2777 | $v_bytes = 0x00000000; |
---|
2778 | while ($v_pos < $v_size) |
---|
2779 | { |
---|
2780 | $v_byte = @fread($this->zip_fd, 1); |
---|
2781 | |
---|
2782 | $v_bytes = ($v_bytes << 8) | Ord($v_byte); |
---|
2783 | |
---|
2784 | if ($v_bytes == 0x504b0506) |
---|
2785 | { |
---|
2786 | $v_pos++; |
---|
2787 | break; |
---|
2788 | } |
---|
2789 | |
---|
2790 | $v_pos++; |
---|
2791 | } |
---|
2792 | |
---|
2793 | if ($v_pos == $v_size) |
---|
2794 | { |
---|
2795 | |
---|
2796 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); |
---|
2797 | |
---|
2798 | return PclZip::errorCode(); |
---|
2799 | } |
---|
2800 | } |
---|
2801 | |
---|
2802 | $v_binary_data = fread($this->zip_fd, 18); |
---|
2803 | |
---|
2804 | if (strlen($v_binary_data) != 18) |
---|
2805 | { |
---|
2806 | |
---|
2807 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); |
---|
2808 | |
---|
2809 | return PclZip::errorCode(); |
---|
2810 | } |
---|
2811 | |
---|
2812 | $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data); |
---|
2813 | |
---|
2814 | if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { |
---|
2815 | |
---|
2816 | if (0) { |
---|
2817 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, |
---|
2818 | 'The central dir is not at the end of the archive.' |
---|
2819 | .' Some trailing bytes exists after the archive.'); |
---|
2820 | |
---|
2821 | return PclZip::errorCode(); |
---|
2822 | } |
---|
2823 | } |
---|
2824 | |
---|
2825 | if ($v_data['comment_size'] != 0) { |
---|
2826 | $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); |
---|
2827 | } |
---|
2828 | else |
---|
2829 | $p_central_dir['comment'] = ''; |
---|
2830 | |
---|
2831 | $p_central_dir['entries'] = $v_data['entries']; |
---|
2832 | $p_central_dir['disk_entries'] = $v_data['disk_entries']; |
---|
2833 | $p_central_dir['offset'] = $v_data['offset']; |
---|
2834 | $p_central_dir['size'] = $v_data['size']; |
---|
2835 | $p_central_dir['disk'] = $v_data['disk']; |
---|
2836 | $p_central_dir['disk_start'] = $v_data['disk_start']; |
---|
2837 | |
---|
2838 | |
---|
2839 | return $v_result; |
---|
2840 | } |
---|
2841 | |
---|
2842 | function privDeleteByRule(&$p_result_list, &$p_options) |
---|
2843 | { |
---|
2844 | $v_result=1; |
---|
2845 | $v_list_detail = array(); |
---|
2846 | |
---|
2847 | if (($v_result=$this->privOpenFd('rb')) != 1) |
---|
2848 | { |
---|
2849 | return $v_result; |
---|
2850 | } |
---|
2851 | |
---|
2852 | $v_central_dir = array(); |
---|
2853 | if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
---|
2854 | { |
---|
2855 | $this->privCloseFd(); |
---|
2856 | return $v_result; |
---|
2857 | } |
---|
2858 | |
---|
2859 | @rewind($this->zip_fd); |
---|
2860 | |
---|
2861 | $v_pos_entry = $v_central_dir['offset']; |
---|
2862 | @rewind($this->zip_fd); |
---|
2863 | if (@fseek($this->zip_fd, $v_pos_entry)) |
---|
2864 | { |
---|
2865 | $this->privCloseFd(); |
---|
2866 | |
---|
2867 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
---|
2868 | |
---|
2869 | return PclZip::errorCode(); |
---|
2870 | } |
---|
2871 | |
---|
2872 | $v_header_list = array(); |
---|
2873 | $j_start = 0; |
---|
2874 | for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
---|
2875 | { |
---|
2876 | |
---|
2877 | $v_header_list[$v_nb_extracted] = array(); |
---|
2878 | if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) |
---|
2879 | { |
---|
2880 | $this->privCloseFd(); |
---|
2881 | |
---|
2882 | return $v_result; |
---|
2883 | } |
---|
2884 | |
---|
2885 | |
---|
2886 | $v_header_list[$v_nb_extracted]['index'] = $i; |
---|
2887 | |
---|
2888 | $v_found = false; |
---|
2889 | |
---|
2890 | if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
---|
2891 | && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
---|
2892 | |
---|
2893 | for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { |
---|
2894 | |
---|
2895 | if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
---|
2896 | |
---|
2897 | if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
---|
2898 | && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
---|
2899 | $v_found = true; |
---|
2900 | } |
---|
2901 | elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) |
---|
2902 | && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
---|
2903 | $v_found = true; |
---|
2904 | } |
---|
2905 | } |
---|
2906 | elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
---|
2907 | $v_found = true; |
---|
2908 | } |
---|
2909 | } |
---|
2910 | } |
---|
2911 | |
---|
2912 | else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) |
---|
2913 | && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { |
---|
2914 | |
---|
2915 | if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { |
---|
2916 | $v_found = true; |
---|
2917 | } |
---|
2918 | } |
---|
2919 | |
---|
2920 | else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
---|
2921 | && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
---|
2922 | |
---|
2923 | if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { |
---|
2924 | $v_found = true; |
---|
2925 | } |
---|
2926 | } |
---|
2927 | |
---|
2928 | else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
---|
2929 | && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
---|
2930 | |
---|
2931 | for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { |
---|
2932 | |
---|
2933 | if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
---|
2934 | $v_found = true; |
---|
2935 | } |
---|
2936 | if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
---|
2937 | $j_start = $j+1; |
---|
2938 | } |
---|
2939 | |
---|
2940 | if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
---|
2941 | break; |
---|
2942 | } |
---|
2943 | } |
---|
2944 | } |
---|
2945 | else { |
---|
2946 | $v_found = true; |
---|
2947 | } |
---|
2948 | |
---|
2949 | if ($v_found) |
---|
2950 | { |
---|
2951 | unset($v_header_list[$v_nb_extracted]); |
---|
2952 | } |
---|
2953 | else |
---|
2954 | { |
---|
2955 | $v_nb_extracted++; |
---|
2956 | } |
---|
2957 | } |
---|
2958 | |
---|
2959 | if ($v_nb_extracted > 0) { |
---|
2960 | |
---|
2961 | $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
---|
2962 | |
---|
2963 | $v_temp_zip = new PclZip($v_zip_temp_name); |
---|
2964 | |
---|
2965 | if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) { |
---|
2966 | $this->privCloseFd(); |
---|
2967 | |
---|
2968 | return $v_result; |
---|
2969 | } |
---|
2970 | |
---|
2971 | for ($i=0; $i<sizeof($v_header_list); $i++) { |
---|
2972 | |
---|
2973 | @rewind($this->zip_fd); |
---|
2974 | if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { |
---|
2975 | $this->privCloseFd(); |
---|
2976 | $v_temp_zip->privCloseFd(); |
---|
2977 | @unlink($v_zip_temp_name); |
---|
2978 | |
---|
2979 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
---|
2980 | |
---|
2981 | return PclZip::errorCode(); |
---|
2982 | } |
---|
2983 | |
---|
2984 | $v_local_header = array(); |
---|
2985 | if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) { |
---|
2986 | $this->privCloseFd(); |
---|
2987 | $v_temp_zip->privCloseFd(); |
---|
2988 | @unlink($v_zip_temp_name); |
---|
2989 | |
---|
2990 | return $v_result; |
---|
2991 | } |
---|
2992 | |
---|
2993 | if ($this->privCheckFileHeaders($v_local_header, |
---|
2994 | $v_header_list[$i]) != 1) { |
---|
2995 | } |
---|
2996 | unset($v_local_header); |
---|
2997 | |
---|
2998 | if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) { |
---|
2999 | $this->privCloseFd(); |
---|
3000 | $v_temp_zip->privCloseFd(); |
---|
3001 | @unlink($v_zip_temp_name); |
---|
3002 | |
---|
3003 | return $v_result; |
---|
3004 | } |
---|
3005 | |
---|
3006 | if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) { |
---|
3007 | $this->privCloseFd(); |
---|
3008 | $v_temp_zip->privCloseFd(); |
---|
3009 | @unlink($v_zip_temp_name); |
---|
3010 | |
---|
3011 | return $v_result; |
---|
3012 | } |
---|
3013 | } |
---|
3014 | |
---|
3015 | $v_offset = @ftell($v_temp_zip->zip_fd); |
---|
3016 | |
---|
3017 | for ($i=0; $i<sizeof($v_header_list); $i++) { |
---|
3018 | if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
---|
3019 | $v_temp_zip->privCloseFd(); |
---|
3020 | $this->privCloseFd(); |
---|
3021 | @unlink($v_zip_temp_name); |
---|
3022 | |
---|
3023 | return $v_result; |
---|
3024 | } |
---|
3025 | |
---|
3026 | $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
---|
3027 | } |
---|
3028 | |
---|
3029 | |
---|
3030 | $v_comment = ''; |
---|
3031 | if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
---|
3032 | $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
---|
3033 | } |
---|
3034 | |
---|
3035 | $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset; |
---|
3036 | |
---|
3037 | if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) { |
---|
3038 | unset($v_header_list); |
---|
3039 | $v_temp_zip->privCloseFd(); |
---|
3040 | $this->privCloseFd(); |
---|
3041 | @unlink($v_zip_temp_name); |
---|
3042 | |
---|
3043 | return $v_result; |
---|
3044 | } |
---|
3045 | |
---|
3046 | $v_temp_zip->privCloseFd(); |
---|
3047 | $this->privCloseFd(); |
---|
3048 | |
---|
3049 | @unlink($this->zipname); |
---|
3050 | |
---|
3051 | PclZipUtilRename($v_zip_temp_name, $this->zipname); |
---|
3052 | |
---|
3053 | unset($v_temp_zip); |
---|
3054 | } |
---|
3055 | |
---|
3056 | else if ($v_central_dir['entries'] != 0) { |
---|
3057 | $this->privCloseFd(); |
---|
3058 | |
---|
3059 | if (($v_result = $this->privOpenFd('wb')) != 1) { |
---|
3060 | return $v_result; |
---|
3061 | } |
---|
3062 | |
---|
3063 | if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) { |
---|
3064 | return $v_result; |
---|
3065 | } |
---|
3066 | |
---|
3067 | $this->privCloseFd(); |
---|
3068 | } |
---|
3069 | |
---|
3070 | return $v_result; |
---|
3071 | } |
---|
3072 | |
---|
3073 | function privDirCheck($p_dir, $p_is_dir=false) |
---|
3074 | { |
---|
3075 | $v_result = 1; |
---|
3076 | |
---|
3077 | |
---|
3078 | if (($p_is_dir) && (substr($p_dir, -1)=='/')) |
---|
3079 | { |
---|
3080 | $p_dir = substr($p_dir, 0, strlen($p_dir)-1); |
---|
3081 | } |
---|
3082 | |
---|
3083 | if ((is_dir($p_dir)) || ($p_dir == "")) |
---|
3084 | { |
---|
3085 | return 1; |
---|
3086 | } |
---|
3087 | |
---|
3088 | $p_parent_dir = dirname($p_dir); |
---|
3089 | |
---|
3090 | if ($p_parent_dir != $p_dir) |
---|
3091 | { |
---|
3092 | if ($p_parent_dir != "") |
---|
3093 | { |
---|
3094 | if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) |
---|
3095 | { |
---|
3096 | return $v_result; |
---|
3097 | } |
---|
3098 | } |
---|
3099 | } |
---|
3100 | |
---|
3101 | if (!@mkdir($p_dir, 0777)) |
---|
3102 | { |
---|
3103 | PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); |
---|
3104 | |
---|
3105 | return PclZip::errorCode(); |
---|
3106 | } |
---|
3107 | |
---|
3108 | return $v_result; |
---|
3109 | } |
---|
3110 | |
---|
3111 | function privMerge(&$p_archive_to_add) |
---|
3112 | { |
---|
3113 | $v_result=1; |
---|
3114 | |
---|
3115 | if (!is_file($p_archive_to_add->zipname)) |
---|
3116 | { |
---|
3117 | |
---|
3118 | $v_result = 1; |
---|
3119 | |
---|
3120 | return $v_result; |
---|
3121 | } |
---|
3122 | |
---|
3123 | if (!is_file($this->zipname)) |
---|
3124 | { |
---|
3125 | |
---|
3126 | $v_result = $this->privDuplicate($p_archive_to_add->zipname); |
---|
3127 | |
---|
3128 | return $v_result; |
---|
3129 | } |
---|
3130 | |
---|
3131 | if (($v_result=$this->privOpenFd('rb')) != 1) |
---|
3132 | { |
---|
3133 | return $v_result; |
---|
3134 | } |
---|
3135 | |
---|
3136 | $v_central_dir = array(); |
---|
3137 | if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
---|
3138 | { |
---|
3139 | $this->privCloseFd(); |
---|
3140 | return $v_result; |
---|
3141 | } |
---|
3142 | |
---|
3143 | @rewind($this->zip_fd); |
---|
3144 | |
---|
3145 | if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) |
---|
3146 | { |
---|
3147 | $this->privCloseFd(); |
---|
3148 | |
---|
3149 | return $v_result; |
---|
3150 | } |
---|
3151 | |
---|
3152 | $v_central_dir_to_add = array(); |
---|
3153 | if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) |
---|
3154 | { |
---|
3155 | $this->privCloseFd(); |
---|
3156 | $p_archive_to_add->privCloseFd(); |
---|
3157 | |
---|
3158 | return $v_result; |
---|
3159 | } |
---|
3160 | |
---|
3161 | @rewind($p_archive_to_add->zip_fd); |
---|
3162 | |
---|
3163 | $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp'; |
---|
3164 | |
---|
3165 | if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
---|
3166 | { |
---|
3167 | $this->privCloseFd(); |
---|
3168 | $p_archive_to_add->privCloseFd(); |
---|
3169 | |
---|
3170 | PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
---|
3171 | |
---|
3172 | return PclZip::errorCode(); |
---|
3173 | } |
---|
3174 | |
---|
3175 | $v_size = $v_central_dir['offset']; |
---|
3176 | while ($v_size != 0) |
---|
3177 | { |
---|
3178 | $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
---|
3179 | $v_buffer = fread($this->zip_fd, $v_read_size); |
---|
3180 | @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
---|
3181 | $v_size -= $v_read_size; |
---|
3182 | } |
---|
3183 | |
---|
3184 | $v_size = $v_central_dir_to_add['offset']; |
---|
3185 | while ($v_size != 0) |
---|
3186 | { |
---|
3187 | $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
---|
3188 | $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); |
---|
3189 | @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
---|
3190 | $v_size -= $v_read_size; |
---|
3191 | } |
---|
3192 | |
---|
3193 | $v_offset = @ftell($v_zip_temp_fd); |
---|
3194 | |
---|
3195 | $v_size = $v_central_dir['size']; |
---|
3196 | while ($v_size != 0) |
---|
3197 | { |
---|
3198 | $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
---|
3199 | $v_buffer = @fread($this->zip_fd, $v_read_size); |
---|
3200 | @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
---|
3201 | $v_size -= $v_read_size; |
---|
3202 | } |
---|
3203 | |
---|
3204 | $v_size = $v_central_dir_to_add['size']; |
---|
3205 | while ($v_size != 0) |
---|
3206 | { |
---|
3207 | $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
---|
3208 | $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); |
---|
3209 | @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
---|
3210 | $v_size -= $v_read_size; |
---|
3211 | } |
---|
3212 | |
---|
3213 | $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment']; |
---|
3214 | |
---|
3215 | $v_size = @ftell($v_zip_temp_fd)-$v_offset; |
---|
3216 | |
---|
3217 | $v_swap = $this->zip_fd; |
---|
3218 | $this->zip_fd = $v_zip_temp_fd; |
---|
3219 | $v_zip_temp_fd = $v_swap; |
---|
3220 | |
---|
3221 | if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) |
---|
3222 | { |
---|
3223 | $this->privCloseFd(); |
---|
3224 | $p_archive_to_add->privCloseFd(); |
---|
3225 | @fclose($v_zip_temp_fd); |
---|
3226 | $this->zip_fd = null; |
---|
3227 | |
---|
3228 | unset($v_header_list); |
---|
3229 | |
---|
3230 | return $v_result; |
---|
3231 | } |
---|
3232 | |
---|
3233 | $v_swap = $this->zip_fd; |
---|
3234 | $this->zip_fd = $v_zip_temp_fd; |
---|
3235 | $v_zip_temp_fd = $v_swap; |
---|
3236 | |
---|
3237 | $this->privCloseFd(); |
---|
3238 | $p_archive_to_add->privCloseFd(); |
---|
3239 | |
---|
3240 | @fclose($v_zip_temp_fd); |
---|
3241 | |
---|
3242 | @unlink($this->zipname); |
---|
3243 | |
---|
3244 | PclZipUtilRename($v_zip_temp_name, $this->zipname); |
---|
3245 | |
---|
3246 | return $v_result; |
---|
3247 | } |
---|
3248 | |
---|
3249 | function privDuplicate($p_archive_filename) |
---|
3250 | { |
---|
3251 | $v_result=1; |
---|
3252 | |
---|
3253 | if (!is_file($p_archive_filename)) |
---|
3254 | { |
---|
3255 | |
---|
3256 | $v_result = 1; |
---|
3257 | |
---|
3258 | return $v_result; |
---|
3259 | } |
---|
3260 | |
---|
3261 | if (($v_result=$this->privOpenFd('wb')) != 1) |
---|
3262 | { |
---|
3263 | return $v_result; |
---|
3264 | } |
---|
3265 | |
---|
3266 | if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) |
---|
3267 | { |
---|
3268 | $this->privCloseFd(); |
---|
3269 | |
---|
3270 | PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); |
---|
3271 | |
---|
3272 | return PclZip::errorCode(); |
---|
3273 | } |
---|
3274 | |
---|
3275 | $v_size = filesize($p_archive_filename); |
---|
3276 | while ($v_size != 0) |
---|
3277 | { |
---|
3278 | $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
---|
3279 | $v_buffer = fread($v_zip_temp_fd, $v_read_size); |
---|
3280 | @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
---|
3281 | $v_size -= $v_read_size; |
---|
3282 | } |
---|
3283 | |
---|
3284 | $this->privCloseFd(); |
---|
3285 | |
---|
3286 | @fclose($v_zip_temp_fd); |
---|
3287 | |
---|
3288 | return $v_result; |
---|
3289 | } |
---|
3290 | |
---|
3291 | function privErrorLog($p_error_code=0, $p_error_string='') |
---|
3292 | { |
---|
3293 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
---|
3294 | PclError($p_error_code, $p_error_string); |
---|
3295 | } |
---|
3296 | else { |
---|
3297 | $this->error_code = $p_error_code; |
---|
3298 | $this->error_string = $p_error_string; |
---|
3299 | } |
---|
3300 | } |
---|
3301 | |
---|
3302 | function privErrorReset() |
---|
3303 | { |
---|
3304 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
---|
3305 | PclErrorReset(); |
---|
3306 | } |
---|
3307 | else { |
---|
3308 | $this->error_code = 0; |
---|
3309 | $this->error_string = ''; |
---|
3310 | } |
---|
3311 | } |
---|
3312 | |
---|
3313 | function privDecrypt($p_encryption_header, &$p_buffer, $p_size, $p_crc) |
---|
3314 | { |
---|
3315 | $v_result=1; |
---|
3316 | |
---|
3317 | $v_pwd = "test"; |
---|
3318 | |
---|
3319 | $p_buffer = PclZipUtilZipDecrypt($p_buffer, $p_size, $p_encryption_header, |
---|
3320 | $p_crc, $v_pwd); |
---|
3321 | |
---|
3322 | return $v_result; |
---|
3323 | } |
---|
3324 | |
---|
3325 | function privDisableMagicQuotes() |
---|
3326 | { |
---|
3327 | $v_result=1; |
---|
3328 | |
---|
3329 | if ( (!function_exists("get_magic_quotes_runtime")) |
---|
3330 | || (!function_exists("set_magic_quotes_runtime"))) { |
---|
3331 | return $v_result; |
---|
3332 | } |
---|
3333 | |
---|
3334 | if ($this->magic_quotes_status != -1) { |
---|
3335 | return $v_result; |
---|
3336 | } |
---|
3337 | |
---|
3338 | $this->magic_quotes_status = @get_magic_quotes_runtime(); |
---|
3339 | |
---|
3340 | if ($this->magic_quotes_status == 1) { |
---|
3341 | @set_magic_quotes_runtime(0); |
---|
3342 | } |
---|
3343 | |
---|
3344 | return $v_result; |
---|
3345 | } |
---|
3346 | |
---|
3347 | function privSwapBackMagicQuotes() |
---|
3348 | { |
---|
3349 | $v_result=1; |
---|
3350 | |
---|
3351 | if ( (!function_exists("get_magic_quotes_runtime")) |
---|
3352 | || (!function_exists("set_magic_quotes_runtime"))) { |
---|
3353 | return $v_result; |
---|
3354 | } |
---|
3355 | |
---|
3356 | if ($this->magic_quotes_status != -1) { |
---|
3357 | return $v_result; |
---|
3358 | } |
---|
3359 | |
---|
3360 | if ($this->magic_quotes_status == 1) { |
---|
3361 | @set_magic_quotes_runtime($this->magic_quotes_status); |
---|
3362 | } |
---|
3363 | |
---|
3364 | return $v_result; |
---|
3365 | } |
---|
3366 | |
---|
3367 | } |
---|
3368 | |
---|
3369 | function PclZipUtilPathReduction($p_dir) |
---|
3370 | { |
---|
3371 | $v_result = ""; |
---|
3372 | |
---|
3373 | if ($p_dir != "") { |
---|
3374 | $v_list = explode("/", $p_dir); |
---|
3375 | |
---|
3376 | $v_skip = 0; |
---|
3377 | for ($i=sizeof($v_list)-1; $i>=0; $i--) { |
---|
3378 | if ($v_list[$i] == ".") { |
---|
3379 | } |
---|
3380 | else if ($v_list[$i] == "..") { |
---|
3381 | $v_skip++; |
---|
3382 | } |
---|
3383 | else if ($v_list[$i] == "") { |
---|
3384 | if ($i == 0) { |
---|
3385 | $v_result = "/".$v_result; |
---|
3386 | if ($v_skip > 0) { |
---|
3387 | $v_result = $p_dir; |
---|
3388 | $v_skip = 0; |
---|
3389 | } |
---|
3390 | } |
---|
3391 | else if ($i == (sizeof($v_list)-1)) { |
---|
3392 | $v_result = $v_list[$i]; |
---|
3393 | } |
---|
3394 | else { |
---|
3395 | } |
---|
3396 | } |
---|
3397 | else { |
---|
3398 | if ($v_skip > 0) { |
---|
3399 | $v_skip--; |
---|
3400 | } |
---|
3401 | else { |
---|
3402 | $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); |
---|
3403 | } |
---|
3404 | } |
---|
3405 | } |
---|
3406 | |
---|
3407 | if ($v_skip > 0) { |
---|
3408 | while ($v_skip > 0) { |
---|
3409 | $v_result = '../'.$v_result; |
---|
3410 | $v_skip--; |
---|
3411 | } |
---|
3412 | } |
---|
3413 | } |
---|
3414 | |
---|
3415 | return $v_result; |
---|
3416 | } |
---|
3417 | |
---|
3418 | function PclZipUtilPathInclusion($p_dir, $p_path) |
---|
3419 | { |
---|
3420 | $v_result = 1; |
---|
3421 | |
---|
3422 | if ( ($p_dir == '.') |
---|
3423 | || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { |
---|
3424 | $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); |
---|
3425 | } |
---|
3426 | if ( ($p_path == '.') |
---|
3427 | || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { |
---|
3428 | $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); |
---|
3429 | } |
---|
3430 | |
---|
3431 | $v_list_dir = explode("/", $p_dir); |
---|
3432 | $v_list_dir_size = sizeof($v_list_dir); |
---|
3433 | $v_list_path = explode("/", $p_path); |
---|
3434 | $v_list_path_size = sizeof($v_list_path); |
---|
3435 | |
---|
3436 | $i = 0; |
---|
3437 | $j = 0; |
---|
3438 | while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) { |
---|
3439 | |
---|
3440 | if ($v_list_dir[$i] == '') { |
---|
3441 | $i++; |
---|
3442 | continue; |
---|
3443 | } |
---|
3444 | if ($v_list_path[$j] == '') { |
---|
3445 | $j++; |
---|
3446 | continue; |
---|
3447 | } |
---|
3448 | |
---|
3449 | if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { |
---|
3450 | $v_result = 0; |
---|
3451 | } |
---|
3452 | |
---|
3453 | $i++; |
---|
3454 | $j++; |
---|
3455 | } |
---|
3456 | |
---|
3457 | if ($v_result) { |
---|
3458 | while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; |
---|
3459 | while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; |
---|
3460 | |
---|
3461 | if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { |
---|
3462 | $v_result = 2; |
---|
3463 | } |
---|
3464 | else if ($i < $v_list_dir_size) { |
---|
3465 | $v_result = 0; |
---|
3466 | } |
---|
3467 | } |
---|
3468 | |
---|
3469 | return $v_result; |
---|
3470 | } |
---|
3471 | |
---|
3472 | function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) |
---|
3473 | { |
---|
3474 | $v_result = 1; |
---|
3475 | |
---|
3476 | if ($p_mode==0) |
---|
3477 | { |
---|
3478 | while ($p_size != 0) |
---|
3479 | { |
---|
3480 | $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
---|
3481 | $v_buffer = @fread($p_src, $v_read_size); |
---|
3482 | @fwrite($p_dest, $v_buffer, $v_read_size); |
---|
3483 | $p_size -= $v_read_size; |
---|
3484 | } |
---|
3485 | } |
---|
3486 | else if ($p_mode==1) |
---|
3487 | { |
---|
3488 | while ($p_size != 0) |
---|
3489 | { |
---|
3490 | $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
---|
3491 | $v_buffer = @gzread($p_src, $v_read_size); |
---|
3492 | @fwrite($p_dest, $v_buffer, $v_read_size); |
---|
3493 | $p_size -= $v_read_size; |
---|
3494 | } |
---|
3495 | } |
---|
3496 | else if ($p_mode==2) |
---|
3497 | { |
---|
3498 | while ($p_size != 0) |
---|
3499 | { |
---|
3500 | $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
---|
3501 | $v_buffer = @fread($p_src, $v_read_size); |
---|
3502 | @gzwrite($p_dest, $v_buffer, $v_read_size); |
---|
3503 | $p_size -= $v_read_size; |
---|
3504 | } |
---|
3505 | } |
---|
3506 | else if ($p_mode==3) |
---|
3507 | { |
---|
3508 | while ($p_size != 0) |
---|
3509 | { |
---|
3510 | $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
---|
3511 | $v_buffer = @gzread($p_src, $v_read_size); |
---|
3512 | @gzwrite($p_dest, $v_buffer, $v_read_size); |
---|
3513 | $p_size -= $v_read_size; |
---|
3514 | } |
---|
3515 | } |
---|
3516 | |
---|
3517 | return $v_result; |
---|
3518 | } |
---|
3519 | |
---|
3520 | function PclZipUtilRename($p_src, $p_dest) |
---|
3521 | { |
---|
3522 | $v_result = 1; |
---|
3523 | |
---|
3524 | if (!@rename($p_src, $p_dest)) { |
---|
3525 | |
---|
3526 | if (!@copy($p_src, $p_dest)) { |
---|
3527 | $v_result = 0; |
---|
3528 | } |
---|
3529 | else if (!@unlink($p_src)) { |
---|
3530 | $v_result = 0; |
---|
3531 | } |
---|
3532 | } |
---|
3533 | |
---|
3534 | return $v_result; |
---|
3535 | } |
---|
3536 | |
---|
3537 | function PclZipUtilOptionText($p_option) |
---|
3538 | { |
---|
3539 | |
---|
3540 | $v_list = get_defined_constants(); |
---|
3541 | for (reset($v_list); $v_key = key($v_list); next($v_list)) { |
---|
3542 | $v_prefix = substr($v_key, 0, 10); |
---|
3543 | if (( ($v_prefix == 'PCLZIP_OPT') |
---|
3544 | || ($v_prefix == 'PCLZIP_CB_') |
---|
3545 | || ($v_prefix == 'PCLZIP_ATT')) |
---|
3546 | && ($v_list[$v_key] == $p_option)) { |
---|
3547 | return $v_key; |
---|
3548 | } |
---|
3549 | } |
---|
3550 | |
---|
3551 | $v_result = 'Unknown'; |
---|
3552 | |
---|
3553 | return $v_result; |
---|
3554 | } |
---|
3555 | |
---|
3556 | function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true) |
---|
3557 | { |
---|
3558 | if (stristr(php_uname(), 'windows')) { |
---|
3559 | if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { |
---|
3560 | $p_path = substr($p_path, $v_position+1); |
---|
3561 | } |
---|
3562 | if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
---|
3563 | $p_path = strtr($p_path, '\\', '/'); |
---|
3564 | } |
---|
3565 | } |
---|
3566 | return $p_path; |
---|
3567 | } |
---|
3568 | ?> |
---|