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