1
|
|
|
<?php |
2
|
|
|
if(!defined('AJAX_INIT_DONE')) |
3
|
|
|
{ |
4
|
|
|
die('Permission denied'); |
5
|
|
|
} |
6
|
|
|
?><?php |
7
|
|
|
/** |
8
|
|
|
* function avaialble to the file manager |
9
|
|
|
* @author Logan Cai (cailongqun [at] yahoo [dot] com [dot] cn) |
10
|
|
|
* @link www.phpletter.com |
11
|
|
|
* @since 22/April/2007 |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "config.php"); |
15
|
|
|
/** |
16
|
|
|
* force to ensure existence of stripos |
17
|
|
|
*/ |
18
|
|
|
if (!function_exists("stripos")) |
19
|
|
|
{ |
20
|
|
|
function stripos($str,$needle,$offset=0) |
21
|
|
|
{ |
22
|
|
|
return @strpos(strtolower($str),strtolower($needle),$offset); |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
/** |
26
|
|
|
* get the current Url but not the query string specified in $excls |
27
|
|
|
* |
28
|
|
|
* @param array $excls specify those unwanted query string |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
function getCurrentUrl($excls=array()) |
32
|
|
|
{ |
33
|
|
|
$output = $_SERVER['PHP_SELF']; |
34
|
|
|
$count = 1; |
35
|
|
|
foreach($_GET as $k=>$v) |
36
|
|
|
{ |
37
|
|
|
if(array_search($k, $excls) ===false) |
38
|
|
|
{ |
39
|
|
|
$strAppend = "&"; |
40
|
|
|
if($count == 1) |
41
|
|
|
{ |
42
|
|
|
$strAppend = "?"; |
43
|
|
|
$count++; |
44
|
|
|
} |
45
|
|
|
$output .= $strAppend . urlencode($k) . "=" . urlencode($v); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
return $output; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* print out an array |
53
|
|
|
* |
54
|
|
|
* @param array $array |
55
|
|
|
*/ |
56
|
|
|
function displayArray($array, $comments='') |
57
|
|
|
{ |
58
|
|
|
echo "<pre>"; |
59
|
|
|
echo $comments; |
60
|
|
|
print_r($array); |
61
|
|
|
echo $comments; |
62
|
|
|
echo "</pre>"; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* check if a file extension is permitted |
69
|
|
|
* |
70
|
|
|
* @param string $filePath |
71
|
|
|
* @param array $validExts |
72
|
|
|
* @param array $invalidExts |
73
|
|
|
* @return boolean |
74
|
|
|
*/ |
75
|
|
|
function isValidExt($filePath, $validExts, $invalidExts=array()) |
76
|
|
|
{ |
77
|
|
|
$tem = array(); |
78
|
|
|
|
79
|
|
View Code Duplication |
if(sizeof($validExts)) |
80
|
|
|
{ |
81
|
|
|
foreach($validExts as $k=>$v) |
82
|
|
|
{ |
83
|
|
|
$tem[$k] = strtolower(trim($v)); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
$validExts = $tem; |
87
|
|
|
$tem = array(); |
88
|
|
View Code Duplication |
if(sizeof($invalidExts)) |
89
|
|
|
{ |
90
|
|
|
foreach($invalidExts as $k=>$v) |
91
|
|
|
{ |
92
|
|
|
$tem[$k] = strtolower(trim($v)); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
$invalidExts = $tem; |
96
|
|
|
if(sizeof($validExts) && sizeof($invalidExts)) |
97
|
|
|
{ |
98
|
|
|
foreach($validExts as $k=>$ext) |
99
|
|
|
{ |
100
|
|
|
if(array_search($ext, $invalidExts) !== false) |
101
|
|
|
{ |
102
|
|
|
unset($validExts[$k]); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
if(sizeof($validExts)) |
107
|
|
|
{ |
108
|
|
|
if(array_search(strtolower(getFileExt($filePath)), $validExts) !== false) |
109
|
|
|
{ |
110
|
|
|
return true; |
111
|
|
|
}else |
112
|
|
|
{ |
113
|
|
|
return false; |
114
|
|
|
} |
115
|
|
|
}elseif(array_search(strtolower(getFileExt($filePath)), $invalidExts) === false) |
116
|
|
|
{ |
117
|
|
|
return true; |
118
|
|
|
}else |
119
|
|
|
{ |
120
|
|
|
return false; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
|
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* transform file relative path to absolute path |
130
|
|
|
* @param string $value the path to the file |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
function relToAbs($value) |
134
|
|
|
{ |
135
|
|
|
return backslashToSlash(preg_replace("/(\\\\)/","\\", getRealPath($value))); |
136
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
function getRelativeFileUrl($value, $relativeTo) |
140
|
|
|
{ |
141
|
|
|
$output = ''; |
142
|
|
|
$wwwroot = removeTrailingSlash(backslashToSlash(getRootPath())); |
143
|
|
|
$urlprefix = ''; |
144
|
|
|
$urlsuffix = ''; |
145
|
|
|
$value = backslashToSlash(getRealPath($value)); |
146
|
|
|
$pos = strpos($value, $wwwroot); |
147
|
|
|
if ($pos !== false && $pos == 0) |
148
|
|
|
{ |
149
|
|
|
$output = $urlprefix . substr($value, strlen($wwwroot)) . $urlsuffix; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
/** |
153
|
|
|
* replace slash with backslash |
154
|
|
|
* |
155
|
|
|
* @param string $value the path to the file |
156
|
|
|
* @return string |
157
|
|
|
*/ |
158
|
|
|
function slashToBackslash($value) { |
159
|
|
|
return str_replace("/", DIRECTORY_SEPARATOR, $value); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* replace backslash with slash |
164
|
|
|
* |
165
|
|
|
* @param string $value the path to the file |
166
|
|
|
* @return string |
167
|
|
|
*/ |
168
|
|
|
function backslashToSlash($value) { |
169
|
|
|
return str_replace(DIRECTORY_SEPARATOR, "/", $value); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* removes the trailing slash |
174
|
|
|
* |
175
|
|
|
* @param string $value |
176
|
|
|
* @return string |
177
|
|
|
*/ |
178
|
|
|
function removeTrailingSlash($value) { |
179
|
|
|
if(preg_match('@^.+/$@i', $value)) |
180
|
|
|
{ |
181
|
|
|
$value = substr($value, 0, strlen($value)-1); |
182
|
|
|
} |
183
|
|
|
return $value; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* append a trailing slash |
188
|
|
|
* |
189
|
|
|
* @param string $value |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
|
|
function addTrailingSlash($value) |
193
|
|
|
{ |
194
|
|
|
if(preg_match('@^.*[^/]{1}$@i', $value)) |
195
|
|
|
{ |
196
|
|
|
$value .= '/'; |
197
|
|
|
} |
198
|
|
|
return $value; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* transform a file path to user friendly |
203
|
|
|
* |
204
|
|
|
* @param string $value |
205
|
|
|
* @return string |
206
|
|
|
*/ |
207
|
|
|
function transformFilePath($value) { |
208
|
|
|
$rootPath = addTrailingSlash(backslashToSlash(getRealPath(CONFIG_SYS_ROOT_PATH))); |
209
|
|
|
$value = addTrailingSlash(backslashToSlash(getRealPath($value))); |
210
|
|
|
if(!empty($rootPath) && ($i = strpos($value, $rootPath)) !== false) |
211
|
|
|
{ |
212
|
|
|
$value = ($i == 0?substr($value, strlen($rootPath)):"/"); |
213
|
|
|
} |
214
|
|
|
$value = prependSlash($value); |
215
|
|
|
return $value; |
216
|
|
|
} |
217
|
|
|
/** |
218
|
|
|
* prepend slash |
219
|
|
|
* |
220
|
|
|
* @param string $value |
221
|
|
|
* @return string |
222
|
|
|
*/ |
223
|
|
|
function prependSlash($value) |
224
|
|
|
{ |
225
|
|
|
if (($value && $value[0] != '/') || !$value ) |
226
|
|
|
{ |
227
|
|
|
$value = "/" . $value; |
228
|
|
|
} |
229
|
|
|
return $value; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
|
233
|
|
|
function writeInfo($data, $die = false) |
234
|
|
|
{ |
235
|
|
|
|
236
|
|
|
/* $fp = @fopen(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'data.php', 'w+'); |
|
|
|
|
237
|
|
|
$data = '<?php |
238
|
|
|
die(); |
239
|
|
|
?>' . "\n" . $data; |
240
|
|
|
@fwrite($fp, $data); |
241
|
|
|
@fwrite($fp, "\n\n" . date('d/M/Y H:i:s') ); |
242
|
|
|
@fclose($fp); |
243
|
|
|
if($die) |
244
|
|
|
{ |
245
|
|
|
die(); |
246
|
|
|
}*/ |
247
|
|
|
|
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* no cachable header |
252
|
|
|
*/ |
253
|
|
|
function addNoCacheHeaders() { |
254
|
|
|
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); |
255
|
|
|
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
256
|
|
|
header("Cache-Control: no-store, no-cache, must-revalidate"); |
257
|
|
|
header("Cache-Control: post-check=0, pre-check=0", false); |
258
|
|
|
header("Pragma: no-cache"); |
259
|
|
|
} |
260
|
|
|
/** |
261
|
|
|
* add extra query stiring to a url |
262
|
|
|
* @param string $baseUrl |
263
|
|
|
* @param string $extra the query string added to the base url |
264
|
|
|
*/ |
265
|
|
View Code Duplication |
function appendQueryString($baseUrl, $extra) |
266
|
|
|
{ |
267
|
|
|
$output = $baseUrl; |
268
|
|
|
if(!empty($extra)) |
269
|
|
|
{ |
270
|
|
|
if(strpos($baseUrl, "?") !== false) |
271
|
|
|
{ |
272
|
|
|
$output .= "&" . $extra; |
273
|
|
|
}else |
274
|
|
|
{ |
275
|
|
|
$output .= "?" . $extra; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
return $output; |
280
|
|
|
} |
281
|
|
|
/** |
282
|
|
|
* make the query strin from $_GET, but excluding those specified by $excluded |
283
|
|
|
* |
284
|
|
|
* @param array $excluded |
285
|
|
|
* @return string |
286
|
|
|
*/ |
287
|
|
|
function makeQueryString($excluded=array()) |
288
|
|
|
{ |
289
|
|
|
$output = ''; |
290
|
|
|
$count = 1; |
291
|
|
|
foreach($_GET as $k=>$v) |
292
|
|
|
{ |
293
|
|
|
if(array_search($k, $excluded) === false) |
294
|
|
|
{ |
295
|
|
|
$output .= ($count>1?'&':'') . (urlencode($k) . "=" . urlencode($v)); |
296
|
|
|
$count++; |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
return $output; |
300
|
|
|
} |
301
|
|
|
/** |
302
|
|
|
* get parent path from specific path |
303
|
|
|
* |
304
|
|
|
* @param string $value |
305
|
|
|
* @return string |
306
|
|
|
*/ |
307
|
|
View Code Duplication |
function getParentPath($value) |
308
|
|
|
{ |
309
|
|
|
$value = removeTrailingSlash(backslashToSlash($value)); |
310
|
|
|
if(false !== ($index = strrpos($value, "/")) ) |
311
|
|
|
{ |
312
|
|
|
return substr($value, 0, $index); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* check if the file/folder is sit under the root |
320
|
|
|
* |
321
|
|
|
* @param string $value |
322
|
|
|
* @return boolean |
323
|
|
|
*/ |
324
|
|
View Code Duplication |
function isUnderRoot($value) |
325
|
|
|
{ |
326
|
|
|
$roorPath = strtolower(addTrailingSlash(backslashToSlash(getRealPath(CONFIG_SYS_ROOT_PATH)))); |
327
|
|
|
if(file_exists($value) && @strpos(strtolower(addTrailingSlash(backslashToSlash(getRealPath($value)))), $roorPath) === 0 ) |
328
|
|
|
{ |
329
|
|
|
return true; |
330
|
|
|
} |
331
|
|
|
return false; |
332
|
|
|
} |
333
|
|
|
/** |
334
|
|
|
* check if a file under the session folder |
335
|
|
|
* |
336
|
|
|
* @param string $value |
337
|
|
|
* @return boolean |
338
|
|
|
*/ |
339
|
|
View Code Duplication |
function isUnderSession($value) |
340
|
|
|
{ |
341
|
|
|
global $session; |
342
|
|
|
$sessionPath = strtolower(addTrailingSlash(backslashToSlash(getRealPath($session->getSessionDir())))); |
343
|
|
|
if(file_exists($value) && @strpos(strtolower(addTrailingSlash(backslashToSlash(getRealPath($value)))), $sessionPath) === 0 ) |
344
|
|
|
{ |
345
|
|
|
return true; |
346
|
|
|
} |
347
|
|
|
return false; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* get thumbnail width and height |
353
|
|
|
* |
354
|
|
|
* @param integer $originaleImageWidth |
355
|
|
|
* @param integer $originalImageHeight |
356
|
|
|
* @param integer $thumbnailWidth |
357
|
|
|
* @param integer $thumbnailHeight |
358
|
|
|
* @return array() |
359
|
|
|
*/ |
360
|
|
|
function getThumbWidthHeight( $originaleImageWidth, $originalImageHeight, $thumbnailWidth, $thumbnailHeight) |
361
|
|
|
{ |
362
|
|
|
$outputs = array( "width"=>0, "height"=>0); |
363
|
|
|
$thumbnailWidth = intval($thumbnailWidth); |
364
|
|
|
$thumbnailHeight = intval($thumbnailHeight); |
365
|
|
|
if(!empty($originaleImageWidth) && !empty($originalImageHeight)) |
366
|
|
|
{ |
367
|
|
|
//start to get the thumbnail width & height |
368
|
|
|
if(($thumbnailWidth < 1 && $thumbnailHeight < 1) || ($thumbnailWidth > $originaleImageWidth && $thumbnailHeight > $originalImageHeight )) |
369
|
|
|
{ |
370
|
|
|
$thumbnailWidth =$originaleImageWidth; |
371
|
|
|
$thumbnailHeight = $originalImageHeight; |
372
|
|
|
}elseif($thumbnailWidth < 1) |
373
|
|
|
{ |
374
|
|
|
$thumbnailWidth = floor($thumbnailHeight / $originalImageHeight * $originaleImageWidth); |
375
|
|
|
|
376
|
|
|
}elseif($thumbnailHeight < 1) |
377
|
|
|
{ |
378
|
|
|
$thumbnailHeight = floor($thumbnailWidth / $originaleImageWidth * $originalImageHeight); |
379
|
|
View Code Duplication |
}else |
380
|
|
|
{ |
381
|
|
|
$scale = min($thumbnailWidth/$originaleImageWidth, $thumbnailHeight/$originalImageHeight); |
382
|
|
|
$thumbnailWidth = floor($scale*$originaleImageWidth); |
383
|
|
|
$thumbnailHeight = floor($scale*$originalImageHeight); |
384
|
|
|
} |
385
|
|
|
$outputs['width'] = $thumbnailWidth; |
386
|
|
|
$outputs['height'] = $thumbnailHeight; |
387
|
|
|
} |
388
|
|
|
return $outputs; |
389
|
|
|
|
390
|
|
|
} |
391
|
|
|
/** |
392
|
|
|
* turn to absolute path from relative path |
393
|
|
|
* |
394
|
|
|
* @param string $value |
395
|
|
|
* @return string |
396
|
|
|
*/ |
397
|
|
|
function getAbsPath($value) { |
398
|
|
|
if (substr($value, 0, 1) == "/") |
399
|
|
|
return slashToBackslash(DIR_AJAX_ROOT . $value); |
400
|
|
|
|
401
|
|
|
return slashToBackslash(dirname(__FILE__) . "/" . $value); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* get file/folder base name |
406
|
|
|
* |
407
|
|
|
* @param string $value |
408
|
|
|
* @return string |
409
|
|
|
*/ |
410
|
|
View Code Duplication |
function getBaseName($value) |
411
|
|
|
{ |
412
|
|
|
$value = removeTrailingSlash(backslashToSlash($value)); |
413
|
|
|
|
414
|
|
|
if(false !== ($index = strrpos($value, "/")) ) |
415
|
|
|
{ |
416
|
|
|
return substr($value, $index + 1); |
417
|
|
|
}else |
418
|
|
|
{ |
419
|
|
|
return $value; |
420
|
|
|
} |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
function myRealPath($path) { |
424
|
|
|
|
425
|
|
|
if(strpos($path, ':/') !== false) |
426
|
|
|
{ |
427
|
|
|
return $path; |
428
|
|
|
} |
429
|
|
|
// check if path begins with "/" ie. is absolute |
430
|
|
|
// if it isnt concat with script path |
431
|
|
|
|
432
|
|
|
if (strpos($path,"/") !== 0 ) { |
433
|
|
|
$base=dirname($_SERVER['SCRIPT_FILENAME']); |
434
|
|
|
$path=$base."/".$path; |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
// canonicalize |
438
|
|
|
$path=explode('/', $path); |
439
|
|
|
$newpath=array(); |
440
|
|
|
for ($i=0; $i<sizeof($path); $i++) { |
441
|
|
|
if ($path[$i]==='' || $path[$i]==='.') continue; |
442
|
|
|
if ($path[$i]==='..') { |
443
|
|
|
array_pop($newpath); |
444
|
|
|
continue; |
445
|
|
|
} |
446
|
|
|
array_push($newpath, $path[$i]); |
447
|
|
|
} |
448
|
|
|
$finalpath="/".implode('/', $newpath); |
449
|
|
|
|
450
|
|
|
clearstatcache(); |
451
|
|
|
// check then return valid path or filename |
452
|
|
|
if (file_exists($finalpath)) { |
453
|
|
|
return ($finalpath); |
454
|
|
|
} |
455
|
|
|
else return FALSE; |
456
|
|
|
} |
457
|
|
|
/** |
458
|
|
|
* calcuate realpath for a relative path |
459
|
|
|
* |
460
|
|
|
* @param string $value a relative path |
461
|
|
|
* @return string absolute path of the input |
462
|
|
|
*/ |
463
|
|
|
function getRealPath($value) |
464
|
|
|
{ |
465
|
|
|
$output = ''; |
466
|
|
|
if(($path = realpath($value)) && $path != $value) |
467
|
|
|
{ |
468
|
|
|
$output = $path; |
469
|
|
|
}else |
470
|
|
|
{ |
471
|
|
|
$output = myRealPath($value); |
472
|
|
|
} |
473
|
|
|
return $output; |
474
|
|
|
|
475
|
|
|
} |
476
|
|
|
/** |
477
|
|
|
* get file url |
478
|
|
|
* |
479
|
|
|
* @param string $value |
480
|
|
|
* @return string |
481
|
|
|
*/ |
482
|
|
|
function getFileUrl($value) |
483
|
|
|
{ |
484
|
|
|
$wwwroot = removeTrailingSlash(backslashToSlash(getRootPath())); |
485
|
|
|
|
486
|
|
|
$urlprefix = ''; |
487
|
|
|
$urlsuffix = ''; |
488
|
|
|
|
489
|
|
|
$value = backslashToSlash(getRealPath($value)); |
490
|
|
|
|
491
|
|
|
$pos = stripos($value, $wwwroot); |
492
|
|
|
if ($pos !== false ) |
493
|
|
|
{ |
494
|
|
|
$output = $urlprefix . substr($value, $pos + strlen($wwwroot)) . $urlsuffix; |
495
|
|
|
}else |
496
|
|
|
{ |
497
|
|
|
$output = $value; |
498
|
|
|
} |
499
|
|
|
$protocol = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on' ? 'https' : 'http'); |
500
|
|
|
|
501
|
|
|
// Pick up URL up to /admin and exclude /admin . This is the phpMyFAQ directory |
502
|
|
|
$pmfBase = strrev( |
503
|
|
|
str_replace( |
504
|
|
|
'nimda/', |
505
|
|
|
'', |
506
|
|
|
stristr(strrev(backslashToSlash($_SERVER['HTTP_REFERER'])), 'nimda/') |
507
|
|
|
) |
508
|
|
|
); |
509
|
|
|
if ($pmfBase == $_SERVER['HTTP_HOST']) { |
510
|
|
|
// phpMyFAQ is not in a subdirectory of a domain |
511
|
|
|
$pmfRest = str_replace($_SERVER['DOCUMENT_ROOT'], '', stristr($output, $_SERVER['DOCUMENT_ROOT'])); |
512
|
|
|
} else { |
513
|
|
|
// phpMyFAQ is in a subdirectory of a domain |
514
|
|
|
// extract subdirectory from URL for comparison with path |
515
|
|
|
$pmfSame = strrchr($pmfBase, '/'); |
516
|
|
|
// extract the rest of URL including file name from file path |
517
|
|
|
$pmfRest = str_replace( |
518
|
|
|
$pmfSame, |
519
|
|
|
'', |
520
|
|
|
substr(backslashToSlash($output), strrpos(backslashToSlash($output), $pmfSame)) |
521
|
|
|
); |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
return $pmfBase . $pmfRest ; |
525
|
|
|
|
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* |
530
|
|
|
* transfer file size number to human friendly string |
531
|
|
|
* @param integer $size. |
532
|
|
|
* @return String |
533
|
|
|
*/ |
534
|
|
|
function transformFileSize($size) { |
535
|
|
|
|
536
|
|
|
if ($size > 1048576) |
537
|
|
|
{ |
538
|
|
|
return round($size / 1048576, 1) . " MB"; |
539
|
|
|
}elseif ($size > 1024) |
540
|
|
|
{ |
541
|
|
|
return round($size / 1024, 1) . " KB"; |
542
|
|
|
}elseif($size == '') |
543
|
|
|
{ |
544
|
|
|
return $size; |
545
|
|
|
}else |
546
|
|
|
{ |
547
|
|
|
return $size . " b"; |
548
|
|
|
} |
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
/** |
552
|
|
|
* remove beginging slash |
553
|
|
|
* |
554
|
|
|
* @param string $value |
555
|
|
|
* @return string |
556
|
|
|
*/ |
557
|
|
|
function removeBeginingSlash($value) |
558
|
|
|
{ |
559
|
|
|
$value = backslashToSlash($value); |
560
|
|
|
if(strpos($value, "/") === 0) |
561
|
|
|
{ |
562
|
|
|
$value = substr($value, 1); |
563
|
|
|
} |
564
|
|
|
return $value; |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
/** |
568
|
|
|
* get site root path |
569
|
|
|
* |
570
|
|
|
* @return String. |
571
|
|
|
*/ |
572
|
|
|
function getRootPath() { |
573
|
|
|
$output = ''; |
574
|
|
|
|
575
|
|
|
if (defined('CONFIG_WEBSITE_DOCUMENT_ROOT') && CONFIG_WEBSITE_DOCUMENT_ROOT) |
576
|
|
|
{ |
577
|
|
|
|
578
|
|
|
return slashToBackslash(CONFIG_WEBSITE_DOCUMENT_ROOT); |
579
|
|
|
} |
580
|
|
|
if(isset($_SERVER['DOCUMENT_ROOT']) && ($output = relToAbs($_SERVER['DOCUMENT_ROOT'])) != '' ) |
581
|
|
|
{ |
582
|
|
|
|
583
|
|
|
return $output; |
584
|
|
|
}elseif(isset($_SERVER["SCRIPT_NAME"]) && isset($_SERVER["SCRIPT_FILENAME"]) && ($output = str_replace(backslashToSlash($_SERVER["SCRIPT_NAME"]), '', backslashToSlash($_SERVER["SCRIPT_FILENAME"]))) && is_dir($output)) |
585
|
|
|
{ |
586
|
|
|
|
587
|
|
|
return slashToBackslash($output); |
588
|
|
|
}elseif(isset($_SERVER["SCRIPT_NAME"]) && isset($_SERVER["PATH_TRANSLATED"]) && ($output = str_replace(backslashToSlash($_SERVER["SCRIPT_NAME"]), '', str_replace("//", "/", backslashToSlash($_SERVER["PATH_TRANSLATED"])))) && is_dir($output)) |
589
|
|
|
{ |
590
|
|
|
|
591
|
|
|
return $output; |
592
|
|
|
}else |
593
|
|
|
{ |
594
|
|
|
return ''; |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
return null; |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
|
601
|
|
|
/** |
602
|
|
|
* add beginging slash |
603
|
|
|
* |
604
|
|
|
* @param string $value |
605
|
|
|
* @return string |
606
|
|
|
*/ |
607
|
|
|
function addBeginingSlash($value) |
608
|
|
|
{ |
609
|
|
|
if(strpos($value, "/") !== 0 && !empty($value)) |
610
|
|
|
{ |
611
|
|
|
$value .= "/" . $value; |
612
|
|
|
} |
613
|
|
|
return $value; |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
|
617
|
|
|
|
618
|
|
|
|
619
|
|
|
|
620
|
|
|
/** |
621
|
|
|
* get a file extension |
622
|
|
|
* |
623
|
|
|
* @param string $fileName the path to a file or just the file name |
624
|
|
|
*/ |
625
|
|
|
function getFileExt($filePath) |
626
|
|
|
{ |
627
|
|
|
return @substr(@strrchr($filePath, "."), 1); |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
/** |
631
|
|
|
* reuturn the relative path between two url |
632
|
|
|
* |
633
|
|
|
* @param string $start_dir |
634
|
|
|
* @param string $final_dir |
635
|
|
|
* @return string |
636
|
|
|
*/ |
637
|
|
|
function getRelativePath($start_dir, $final_dir){ |
638
|
|
|
// |
639
|
|
|
$firstPathParts = explode(DIRECTORY_SEPARATOR, $start_dir); |
640
|
|
|
$secondPathParts = explode(DIRECTORY_SEPARATOR, $final_dir); |
641
|
|
|
// |
642
|
|
|
$sameCounter = 0; |
643
|
|
|
for($i = 0; $i < min( count($firstPathParts), count($secondPathParts) ); $i++) { |
644
|
|
|
if( strtolower($firstPathParts[$i]) !== strtolower($secondPathParts[$i]) ) { |
645
|
|
|
break; |
646
|
|
|
} |
647
|
|
|
$sameCounter++; |
648
|
|
|
} |
649
|
|
|
if( $sameCounter == 0 ) { |
650
|
|
|
return $final_dir; |
651
|
|
|
} |
652
|
|
|
// |
653
|
|
|
$newPath = ''; |
654
|
|
|
for($i = $sameCounter; $i < count($firstPathParts); $i++) { |
655
|
|
|
if( $i > $sameCounter ) { |
656
|
|
|
$newPath .= DIRECTORY_SEPARATOR; |
657
|
|
|
} |
658
|
|
|
$newPath .= ".."; |
659
|
|
|
} |
660
|
|
|
if( count($newPath) == 0 ) { |
661
|
|
|
$newPath = "."; |
662
|
|
|
} |
663
|
|
|
for($i = $sameCounter; $i < count($secondPathParts); $i++) { |
664
|
|
|
$newPath .= DIRECTORY_SEPARATOR; |
665
|
|
|
$newPath .= $secondPathParts[$i]; |
666
|
|
|
} |
667
|
|
|
// |
668
|
|
|
return $newPath; |
669
|
|
|
} |
670
|
|
|
/** |
671
|
|
|
* get the php server memory limit |
672
|
|
|
* @return integer |
673
|
|
|
* |
674
|
|
|
*/ |
675
|
|
|
function getMemoryLimit() |
676
|
|
|
{ |
677
|
|
|
$output = @ini_get('memory_limit') or $output = -1 ; |
678
|
|
|
if(intval($output) < 0) |
679
|
|
|
{//unlimited |
680
|
|
|
$output = 999999999999999999; |
681
|
|
|
} |
682
|
|
|
elseif(strpos('g', strtolower($output)) !== false) |
683
|
|
|
{ |
684
|
|
|
$output = intval($output) * 1024 * 1024 * 1024; |
685
|
|
|
}elseif(strpos('k', strtolower($output)) !== false) |
686
|
|
|
{ |
687
|
|
|
$output = intval($output) * 1024 ; |
688
|
|
|
}else |
689
|
|
|
{ |
690
|
|
|
$output = intval($output) * 1024 * 1024; |
691
|
|
|
} |
692
|
|
|
|
693
|
|
|
return $output; |
694
|
|
|
} |
695
|
|
|
/** |
696
|
|
|
* get file content |
697
|
|
|
* |
698
|
|
|
* @param string $path |
699
|
|
|
*/ |
700
|
|
|
function getFileContent($path) |
701
|
|
|
{ |
702
|
|
|
return @file_get_contents($path); |
703
|
|
|
//return str_replace(array("\r", "\n", '"', "\t"), array('', "\\n", '\"', "\\t"), @file_get_contents($path)); |
|
|
|
|
704
|
|
|
} |
705
|
|
|
/** |
706
|
|
|
* get the list of folder under a specified folder |
707
|
|
|
* which will be used for drop-down menu |
708
|
|
|
* @param string $path the path of the specified folder |
709
|
|
|
* @param array $outputs |
710
|
|
|
* @param string $indexNumber |
711
|
|
|
* @param string $prefixNumber the prefix before the index number |
712
|
|
|
* @param string $prefixName the prefix before the folder name |
713
|
|
|
* @return array |
714
|
|
|
*/ |
715
|
|
|
function getFolderListing($path,$indexNumber=null, $prefixNumber =' ', $prefixName =' - ', $outputs=array()) |
716
|
|
|
{ |
717
|
|
|
$path = removeTrailingSlash(backslashToSlash($path)); |
718
|
|
|
if(is_null($indexNumber)) |
719
|
|
|
{ |
720
|
|
|
$outputs[IMG_LBL_ROOT_FOLDER] = removeTrailingSlash(backslashToSlash($path)); |
721
|
|
|
} |
722
|
|
|
$fh = @opendir($path); |
723
|
|
|
if($fh) |
724
|
|
|
{ |
725
|
|
|
$count = 1; |
726
|
|
|
while($file = @readdir($fh)) |
727
|
|
|
{ |
728
|
|
|
$newPath = removeTrailingSlash(backslashToSlash($path . "/" . $file)); |
729
|
|
|
if(isListingDocument($newPath) && $file != '.' && $file != '..' && is_dir($newPath)) |
730
|
|
|
{ |
731
|
|
|
if(!empty($indexNumber)) |
732
|
|
|
{//this is not root folder |
733
|
|
|
|
734
|
|
|
$outputs[$prefixNumber . $indexNumber . "." . $count . $prefixName . $file] = $newPath; |
735
|
|
|
getFolderListing($newPath, $prefixNumber . $indexNumber . "." . $count , $prefixNumber, $prefixName, $outputs); |
736
|
|
|
}else |
737
|
|
|
{//this is root folder |
738
|
|
|
|
739
|
|
|
$outputs[$count . $prefixName . $file] = $newPath; |
740
|
|
|
getFolderListing($newPath, $count, $prefixNumber, $prefixName, $outputs); |
741
|
|
|
} |
742
|
|
|
$count++; |
743
|
|
|
} |
744
|
|
|
} |
745
|
|
|
@closedir($fh); |
746
|
|
|
} |
747
|
|
|
return $outputs; |
748
|
|
|
} |
749
|
|
|
|
750
|
|
|
|
751
|
|
|
/** |
752
|
|
|
* get the valid text editor extension |
753
|
|
|
* which is calcualte from the CONFIG_EDITABALE_VALID_EXTS |
754
|
|
|
* exclude those specified in CONFIG_UPLOAD_INVALID_EXTS |
755
|
|
|
* and those are not specified in CONFIG_UPLOAD_VALID_EXTS |
756
|
|
|
* |
757
|
|
|
* @return array |
758
|
|
|
*/ |
759
|
|
|
function getValidTextEditorExts() |
760
|
|
|
{ |
761
|
|
|
$validEditorExts = explode(',', CONFIG_EDITABLE_VALID_EXTS); |
762
|
|
View Code Duplication |
if(CONFIG_UPLOAD_VALID_EXTS) |
763
|
|
|
{//exclude those exts not shown on CONFIG_UPLOAD_VALID_EXTS |
764
|
|
|
$validUploadExts = explode(',', CONFIG_UPLOAD_VALID_EXTS); |
765
|
|
|
foreach($validEditorExts as $k=>$v) |
766
|
|
|
{ |
767
|
|
|
if(array_search($v, $validUploadExts) === false) |
768
|
|
|
{ |
769
|
|
|
unset($validEditorExts[$k]); |
770
|
|
|
} |
771
|
|
|
} |
772
|
|
|
} |
773
|
|
View Code Duplication |
if(CONFIG_UPLOAD_INVALID_EXTS) |
774
|
|
|
{//exlcude those exists in CONFIG_UPLOAD_INVALID_EXTS |
775
|
|
|
$invalidUploadExts = explode(',', CONFIG_UPLOAD_INVALID_EXTS); |
776
|
|
|
foreach($validEditorExts as $k=>$v) |
777
|
|
|
{ |
778
|
|
|
if(array_search($v, $invalidUploadExts) !== false) |
779
|
|
|
{ |
780
|
|
|
unset($validEditorExts[$k]); |
781
|
|
|
} |
782
|
|
|
} |
783
|
|
|
} |
784
|
|
|
return $validEditorExts; |
785
|
|
|
|
786
|
|
|
} |
787
|
|
|
/** |
788
|
|
|
* check if file name or folder name is valid against a regular expression |
789
|
|
|
* |
790
|
|
|
* @param string $pattern regular expression, separated by , if multiple |
791
|
|
|
* @param string $string |
792
|
|
|
* @return booolean |
793
|
|
|
*/ |
794
|
|
View Code Duplication |
function isValidPattern( $pattern, $string) |
795
|
|
|
{ |
796
|
|
|
if(($pattern)=== '') |
797
|
|
|
{ |
798
|
|
|
return true; |
799
|
|
|
} |
800
|
|
|
else if (strpos($pattern,",")!==false) |
801
|
|
|
{ |
802
|
|
|
$regExps = explode(',', $pattern); |
803
|
|
|
foreach ($regExps as $regExp => $value) |
804
|
|
|
{ |
805
|
|
|
if(eregi($value, $string)) |
806
|
|
|
{ |
807
|
|
|
return true; |
808
|
|
|
} |
809
|
|
|
} |
810
|
|
|
} |
811
|
|
|
else if(eregi($pattern, $string)) |
812
|
|
|
{ |
813
|
|
|
return true; |
814
|
|
|
} |
815
|
|
|
return false; |
816
|
|
|
|
817
|
|
|
} |
818
|
|
|
|
819
|
|
|
|
820
|
|
|
/** |
821
|
|
|
* check if file name or folder name is invalid against a regular expression |
822
|
|
|
* |
823
|
|
|
* @param string $pattern regular expression, separated by , if multiple |
824
|
|
|
* @param string $string |
825
|
|
|
* @return booolean |
826
|
|
|
*/ |
827
|
|
View Code Duplication |
function isInvalidPattern( $pattern, $string) |
828
|
|
|
{ |
829
|
|
|
if(($pattern)=== '') |
830
|
|
|
{ |
831
|
|
|
return false; |
832
|
|
|
} |
833
|
|
|
else if (strpos($pattern,",")!==false) |
834
|
|
|
{ |
835
|
|
|
$regExps = explode(',', $pattern); |
836
|
|
|
foreach ($regExps as $regExp => $value) |
837
|
|
|
{ |
838
|
|
|
if(eregi($value, $string)) |
839
|
|
|
{ |
840
|
|
|
return true; |
841
|
|
|
} |
842
|
|
|
} |
843
|
|
|
} |
844
|
|
|
else if(eregi($pattern, $string)) |
845
|
|
|
{ |
846
|
|
|
return true; |
847
|
|
|
} |
848
|
|
|
return false; |
849
|
|
|
|
850
|
|
|
} |
851
|
|
|
|
852
|
|
|
|
853
|
|
|
/** |
854
|
|
|
* cut the file down to fit the list page |
855
|
|
|
* |
856
|
|
|
* @param string $fileName |
857
|
|
|
*/ |
858
|
|
|
function shortenFileName($fileName, $maxLeng=17, $indicate = '...') |
859
|
|
|
{ |
860
|
|
|
if(strlen($fileName) > $maxLeng) |
861
|
|
|
{ |
862
|
|
|
$fileName = substr($fileName, 0, $maxLeng - strlen($indicate)) . $indicate; |
863
|
|
|
} |
864
|
|
|
return $fileName; |
865
|
|
|
|
866
|
|
|
} |
867
|
|
|
if (!function_exists('mime_content_type')) |
868
|
|
|
{ |
869
|
|
|
function mime_content_type ( $f ) |
870
|
|
|
{ |
871
|
|
|
return trim ( @exec ('file -bi ' . escapeshellarg ( $f ) ) ) ; |
872
|
|
|
} |
873
|
|
|
} |
874
|
|
|
|
875
|
|
|
/** |
876
|
|
|
* check if such document is allowed to shown on the list |
877
|
|
|
* |
878
|
|
|
* @param string $path the path to the document |
879
|
|
|
* @return boolean |
880
|
|
|
*/ |
881
|
|
|
function isListingDocument($path) |
882
|
|
|
{ |
883
|
|
|
$file = basename($path); |
884
|
|
|
if(CONFIG_SYS_PATTERN_FORMAT == 'list') |
885
|
|
|
{// comma delimited vague file/folder name |
886
|
|
|
|
887
|
|
|
|
888
|
|
|
|
889
|
|
|
|
890
|
|
|
if(is_dir($path)) |
891
|
|
|
{ |
892
|
|
|
$includeDir = trimlrm(CONFIG_SYS_INC_DIR_PATTERN); |
893
|
|
|
$excludeDir = trimlrm(CONFIG_SYS_EXC_DIR_PATTERN); |
894
|
|
|
$found_includeDir = strpos($includeDir, $file); |
895
|
|
|
$found_excludeDir = strpos($excludeDir, $file); |
896
|
|
|
if((!CONFIG_SYS_INC_DIR_PATTERN || (!($found_includeDir === FALSE))) && (!CONFIG_SYS_EXC_DIR_PATTERN || (($found_excludeDir === FALSE)))) |
897
|
|
|
{ |
898
|
|
|
return true; |
899
|
|
|
}else |
900
|
|
|
{ |
901
|
|
|
return false; |
902
|
|
|
} |
903
|
|
|
}elseif(is_file($path)) |
904
|
|
|
{ |
905
|
|
|
$includeFile = trimlrm(CONFIG_SYS_INC_FILE_PATTERN); |
906
|
|
|
$excludeFile = trimlrm(CONFIG_SYS_EXC_FILE_PATTERN); |
907
|
|
|
$found_includeFile = strpos($includeFile, $file); |
908
|
|
|
$found_excludeFile = strpos($excludeFile, $file); |
909
|
|
|
if((!CONFIG_SYS_INC_FILE_PATTERN || (!($found_includeFile === FALSE))) && (!CONFIG_SYS_EXC_FILE_PATTERN || (($found_excludeFile === FALSE)))) |
910
|
|
|
{ |
911
|
|
|
return true; |
912
|
|
|
}else |
913
|
|
|
{ |
914
|
|
|
return false; |
915
|
|
|
} |
916
|
|
|
} |
917
|
|
|
}elseif(CONFIG_SYS_PATTERN_FORMAT == 'csv') |
918
|
|
|
{//comma delimited file/folder name |
919
|
|
|
|
920
|
|
|
if(is_dir($path)) |
921
|
|
|
{ |
922
|
|
|
|
923
|
|
|
$includeDir = trimlrm(CONFIG_SYS_INC_DIR_PATTERN); |
924
|
|
|
$excludeDir = trimlrm(CONFIG_SYS_EXC_DIR_PATTERN); |
925
|
|
|
|
926
|
|
View Code Duplication |
if(!empty($includeDir) && !empty($excludeDir)) |
927
|
|
|
{ |
928
|
|
|
|
929
|
|
|
$validDir = explode(',', $includeDir); |
930
|
|
|
|
931
|
|
|
$invalidDir = explode(",", $excludeDir); |
932
|
|
|
|
933
|
|
|
if(array_search(basename($path), $validDir) !== false && array_search(basename($path), $invalidDir) === false) |
934
|
|
|
{ |
935
|
|
|
return true; |
936
|
|
|
}else |
937
|
|
|
{ |
938
|
|
|
return false; |
939
|
|
|
} |
940
|
|
|
}elseif(!empty($includeDir)) |
941
|
|
|
{ |
942
|
|
|
$validDir = explode(',', $includeDir); |
943
|
|
|
if(array_search(basename($path), $validDir) !== false) |
944
|
|
|
{ |
945
|
|
|
return true; |
946
|
|
|
}else |
947
|
|
|
{ |
948
|
|
|
return false; |
949
|
|
|
} |
950
|
|
|
|
951
|
|
|
}elseif(!empty($excludeFile)) |
952
|
|
|
{ |
953
|
|
|
$invalidDir = explode(",", $excludeDir); |
954
|
|
|
if(array_search(basename($path), $invalidDir) === false) |
955
|
|
|
{ |
956
|
|
|
return true; |
957
|
|
|
}else |
958
|
|
|
{ |
959
|
|
|
return false; |
960
|
|
|
} |
961
|
|
|
} |
962
|
|
|
return true; |
963
|
|
|
|
964
|
|
|
}elseif(is_file($path)) |
965
|
|
|
{ |
966
|
|
|
$includeFile = trimlrm(CONFIG_SYS_INC_FILE_PATTERN); |
967
|
|
|
$excludeFile = trimlrm(CONFIG_SYS_EXC_FILE_PATTERN); |
968
|
|
View Code Duplication |
if(!empty($includeFile) && !empty($excludeFile)) |
969
|
|
|
{ |
970
|
|
|
$validFile = explode(',', $includeFile); |
971
|
|
|
$invalidFile = explode(',', $excludeFile); |
972
|
|
|
if(array_search(basename($path), $validFile) !== false && array_search(basename($path), $invalidFile) === false) |
973
|
|
|
{ |
974
|
|
|
return true; |
975
|
|
|
}else |
976
|
|
|
{ |
977
|
|
|
return false; |
978
|
|
|
} |
979
|
|
|
}elseif(!empty($includeFile)) |
980
|
|
|
{ |
981
|
|
|
$validFile = explode(',', $includeFile); |
982
|
|
|
if(array_search(basename($path), $validFile) !== false) |
983
|
|
|
{ |
984
|
|
|
return true; |
985
|
|
|
}else |
986
|
|
|
{ |
987
|
|
|
return false; |
988
|
|
|
} |
989
|
|
|
}elseif(!empty($excludeFile)) |
990
|
|
|
{ |
991
|
|
|
$invalidFile = explode(',', $excludeFile); |
992
|
|
|
if(array_search(basename($path), $invalidFile) === false) |
993
|
|
|
{ |
994
|
|
|
return true; |
995
|
|
|
}else |
996
|
|
|
{ |
997
|
|
|
return false; |
998
|
|
|
} |
999
|
|
|
} |
1000
|
|
|
return true; |
1001
|
|
|
} |
1002
|
|
|
} |
1003
|
|
|
else |
1004
|
|
|
{//regular expression |
1005
|
|
|
if(is_dir($path) ) |
1006
|
|
|
{ |
1007
|
|
|
if(isValidPattern(CONFIG_SYS_INC_DIR_PATTERN, $path) && !isInvalidPattern(CONFIG_SYS_EXC_DIR_PATTERN, $path)) |
1008
|
|
|
{ |
1009
|
|
|
return true; |
1010
|
|
|
}else |
1011
|
|
|
{ |
1012
|
|
|
return false; |
1013
|
|
|
} |
1014
|
|
|
|
1015
|
|
|
}elseif(is_file($path)) |
1016
|
|
|
{ |
1017
|
|
|
if(isValidPattern(CONFIG_SYS_INC_FILE_PATTERN, $path) && !isInvalidPattern(CONFIG_SYS_EXC_FILE_PATTERN, $path) ) |
1018
|
|
|
{ |
1019
|
|
|
return true; |
1020
|
|
|
}else |
1021
|
|
|
{ |
1022
|
|
|
return false; |
1023
|
|
|
} |
1024
|
|
|
} |
1025
|
|
|
} |
1026
|
|
|
return false; |
1027
|
|
|
|
1028
|
|
|
} |
1029
|
|
|
|
1030
|
|
|
/** |
1031
|
|
|
* force to down the specified file |
1032
|
|
|
* |
1033
|
|
|
* @param string $path |
1034
|
|
|
* |
1035
|
|
|
*/ |
1036
|
|
|
function downloadFile($path, $newFileName=null) |
1037
|
|
|
{ |
1038
|
|
|
if(file_exists($path) && is_file($path)) |
1039
|
|
|
{ |
1040
|
|
|
$mimeContentType = 'application/octet-stream'; |
1041
|
|
|
if(function_exists('finfo_open')) |
1042
|
|
|
{ |
1043
|
|
|
if(($fp = @finfo_open($path))) |
1044
|
|
|
{ |
1045
|
|
|
$mimeContentType = @finfo_file($fp, basename($path)); |
1046
|
|
|
@finfo_close($fp); |
1047
|
|
|
} |
1048
|
|
|
|
1049
|
|
|
}elseif(($temMimeContentType = @mime_content_type($path)) && !empty($temMimeContentType)) |
1050
|
|
|
{ |
1051
|
|
|
$mimeContentType = $temMimeContentType; |
1052
|
|
|
} |
1053
|
|
|
|
1054
|
|
|
|
1055
|
|
|
|
1056
|
|
|
|
1057
|
|
|
|
1058
|
|
|
// START ANDR� SILVA DOWNLOAD CODE |
1059
|
|
|
// required for IE, otherwise Content-disposition is ignored |
1060
|
|
|
if(ini_get('zlib.output_compression')) |
1061
|
|
|
ini_set('zlib.output_compression', 'Off'); |
1062
|
|
|
header("Pragma: public"); // required |
1063
|
|
|
header("Expires: 0"); |
1064
|
|
|
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
1065
|
|
|
header("Cache-Control: private",false); // required for certain browsers |
1066
|
|
|
header("Content-Type: " . $mimeContentType ); |
1067
|
|
|
// change, added quotes to allow spaces in filenames, by Rajkumar Singh |
1068
|
|
|
header("Content-Disposition: attachment; filename=\"".(is_null($newFileName)?basename($path):$newFileName)."\";" ); |
1069
|
|
|
header("Content-Transfer-Encoding: binary"); |
1070
|
|
|
header("Content-Length: ".filesize($path)); |
1071
|
|
|
|
1072
|
|
|
readfile($path); |
1073
|
|
|
exit(); |
1074
|
|
|
// END ANDR� SILVA DOWNLOAD CODE |
1075
|
|
|
} |
1076
|
|
|
|
1077
|
|
|
} |
1078
|
|
|
|
1079
|
|
|
/** |
1080
|
|
|
* remove all white spaces |
1081
|
|
|
* |
1082
|
|
|
* @param string $hayStack |
1083
|
|
|
* @param string $whiteSpaceChars |
1084
|
|
|
* @return string |
1085
|
|
|
*/ |
1086
|
|
|
function trimlrm ($hayStack, $whiteSpaceChars="\t\n\r\0\x0B") |
1087
|
|
|
{ |
1088
|
|
|
return str_replace($whiteSpaceChars, '', trim($hayStack)); |
1089
|
|
|
} |
1090
|
|
|
|
1091
|
|
|
/** |
1092
|
|
|
* get the parent path of the specified path |
1093
|
|
|
* |
1094
|
|
|
* @param string $path |
1095
|
|
|
* @return string |
1096
|
|
|
*/ |
1097
|
|
|
function getParentFolderPath($path) |
1098
|
|
|
{ |
1099
|
|
|
$realPath = addTrailingSlash(backslashToSlash(getRealPath($path))); |
1100
|
|
|
$parentRealPath = addTrailingSlash(backslashToSlash(dirname($realPath))); |
1101
|
|
|
$differentPath = addTrailingSlash(substr($realPath, strlen($parentRealPath))); |
1102
|
|
|
$parentPath = substr($path, 0, strlen(addTrailingSlash(backslashToSlash($path))) - strlen($differentPath)); |
1103
|
|
|
if(isUnderRoot($parentPath)) |
1104
|
|
|
{ |
1105
|
|
|
return $parentPath; |
1106
|
|
|
}else |
1107
|
|
|
{ |
1108
|
|
|
return CONFIG_SYS_DEFAULT_PATH; |
1109
|
|
|
} |
1110
|
|
|
} |
1111
|
|
|
|
1112
|
|
|
function getCurrentFolderPath() |
1113
|
|
|
{ |
1114
|
|
|
$folderPathIndex = 'path'; |
1115
|
|
|
$lastVisitedFolderPathIndex = 'ajax_last_visited_folder'; |
1116
|
|
|
if(isset($_GET[$folderPathIndex]) && file_exists($_GET[$folderPathIndex]) && !is_file($_GET[$folderPathIndex]) ) |
1117
|
|
|
{ |
1118
|
|
|
$currentFolderPath = $_GET[$folderPathIndex]; |
1119
|
|
|
} |
1120
|
|
|
elseif(isset($_SESSION[$lastVisitedFolderPathIndex]) && file_exists($_SESSION[$lastVisitedFolderPathIndex]) && !is_file($_SESSION[$lastVisitedFolderPathIndex])) |
1121
|
|
|
{ |
1122
|
|
|
$currentFolderPath = $_SESSION[$lastVisitedFolderPathIndex]; |
1123
|
|
|
}else |
1124
|
|
|
{ |
1125
|
|
|
$currentFolderPath = CONFIG_SYS_DEFAULT_PATH; |
1126
|
|
|
} |
1127
|
|
|
|
1128
|
|
|
$currentFolderPath = (isUnderRoot($currentFolderPath)?backslashToSlash((addTrailingSlash($currentFolderPath))):CONFIG_SYS_DEFAULT_PATH); |
1129
|
|
|
|
1130
|
|
|
//keep track of this folder path in session |
1131
|
|
|
$_SESSION[$lastVisitedFolderPathIndex] = $currentFolderPath; |
1132
|
|
|
|
1133
|
|
|
|
1134
|
|
|
if(!file_exists($currentFolderPath)) |
1135
|
|
|
{ |
1136
|
|
|
die(ERR_FOLDER_NOT_FOUND . $currentFolderPath); |
1137
|
|
|
} |
1138
|
|
|
} |
1139
|
|
|
|
1140
|
|
|
if(!function_exists("imagerotate")) |
1141
|
|
|
{ |
1142
|
|
|
function imagerotate($src_img, $angle, $bicubic=false) |
1143
|
|
|
{ |
1144
|
|
|
// convert degrees to radians |
1145
|
|
|
|
1146
|
|
|
$angle = (360 - $angle) + 180; |
1147
|
|
|
$angle = deg2rad($angle); |
1148
|
|
|
|
1149
|
|
|
$src_x = imagesx($src_img); |
1150
|
|
|
$src_y = imagesy($src_img); |
1151
|
|
|
|
1152
|
|
|
$center_x = floor($src_x/2); |
1153
|
|
|
$center_y = floor($src_y/2); |
1154
|
|
|
|
1155
|
|
|
$rotate = imagecreatetruecolor($src_x, $src_y); |
1156
|
|
|
imagealphablending($rotate, false); |
1157
|
|
|
imagesavealpha($rotate, true); |
1158
|
|
|
|
1159
|
|
|
$cosangle = cos($angle); |
1160
|
|
|
$sinangle = sin($angle); |
1161
|
|
|
|
1162
|
|
|
for ($y = 0; $y < $src_y; $y++) { |
1163
|
|
|
for ($x = 0; $x < $src_x; $x++) { |
1164
|
|
|
// rotate... |
1165
|
|
|
$old_x = (($center_x-$x) * $cosangle + ($center_y-$y) * $sinangle) |
1166
|
|
|
+ $center_x; |
1167
|
|
|
$old_y = (($center_y-$y) * $cosangle - ($center_x-$x) * $sinangle) |
1168
|
|
|
+ $center_y; |
1169
|
|
|
|
1170
|
|
|
if ( $old_x >= 0 && $old_x < $src_x |
1171
|
|
|
&& $old_y >= 0 && $old_y < $src_y ) { |
1172
|
|
|
if ($bicubic == true) { |
1173
|
|
|
$sY = $old_y + 1; |
1174
|
|
|
$siY = $old_y; |
1175
|
|
|
$siY2 = $old_y - 1; |
1176
|
|
|
$sX = $old_x + 1; |
1177
|
|
|
$siX = $old_x; |
1178
|
|
|
$siX2 = $old_x - 1; |
1179
|
|
|
|
1180
|
|
|
$c1 = imagecolorsforindex($src_img, imagecolorat($src_img, $siX, $siY2)); |
1181
|
|
|
$c2 = imagecolorsforindex($src_img, imagecolorat($src_img, $siX, $siY)); |
1182
|
|
|
$c3 = imagecolorsforindex($src_img, imagecolorat($src_img, $siX2, $siY2)); |
1183
|
|
|
$c4 = imagecolorsforindex($src_img, imagecolorat($src_img, $siX2, $siY)); |
1184
|
|
|
|
1185
|
|
|
$r = ($c1['red'] + $c2['red'] + $c3['red'] + $c4['red'] ) << 14; |
1186
|
|
|
$g = ($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) << 6; |
1187
|
|
|
$b = ($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue'] ) >> 2; |
1188
|
|
|
$a = ($c1['alpha'] + $c2['alpha'] + $c3['alpha'] + $c4['alpha'] ) >> 2; |
1189
|
|
|
$color = imagecolorallocatealpha($src_img, $r,$g,$b,$a); |
1190
|
|
|
} else { |
1191
|
|
|
$color = imagecolorat($src_img, $old_x, $old_y); |
1192
|
|
|
} |
1193
|
|
|
} else { |
1194
|
|
|
// this line sets the background colour |
1195
|
|
|
$color = imagecolorallocatealpha($src_img, 255, 255, 255, 127); |
1196
|
|
|
} |
1197
|
|
|
imagesetpixel($rotate, $x, $y, $color); |
1198
|
|
|
} |
1199
|
|
|
} |
1200
|
|
|
return $rotate; |
1201
|
|
|
/* $src_x = @imagesx($src_img); |
|
|
|
|
1202
|
|
|
$src_y = @imagesy($src_img); |
1203
|
|
|
if ($angle == 180) |
1204
|
|
|
{ |
1205
|
|
|
$dest_x = $src_x; |
1206
|
|
|
$dest_y = $src_y; |
1207
|
|
|
} |
1208
|
|
|
elseif ($src_x <= $src_y) |
1209
|
|
|
{ |
1210
|
|
|
$dest_x = $src_y; |
1211
|
|
|
$dest_y = $src_x; |
1212
|
|
|
} |
1213
|
|
|
elseif ($src_x >= $src_y) |
1214
|
|
|
{ |
1215
|
|
|
$dest_x = $src_y; |
1216
|
|
|
$dest_y = $src_x; |
1217
|
|
|
} |
1218
|
|
|
if(function_exists('ImageCreateTrueColor')) |
1219
|
|
|
{ |
1220
|
|
|
$rotate = @ImageCreateTrueColor($dst_w,$dst_h); |
1221
|
|
|
} else { |
1222
|
|
|
$rotate = @ImageCreate($dst_w,$dst_h); |
1223
|
|
|
} |
1224
|
|
|
@imagealphablending($rotate, false); |
1225
|
|
|
|
1226
|
|
|
switch ($angle) |
1227
|
|
|
{ |
1228
|
|
|
case 270: |
1229
|
|
|
for ($y = 0; $y < ($src_y); $y++) |
1230
|
|
|
{ |
1231
|
|
|
for ($x = 0; $x < ($src_x); $x++) |
1232
|
|
|
{ |
1233
|
|
|
$color = imagecolorat($src_img, $x, $y); |
1234
|
|
|
imagesetpixel($rotate, $dest_x - $y - 1, $x, $color); |
1235
|
|
|
} |
1236
|
|
|
} |
1237
|
|
|
break; |
1238
|
|
|
case 90: |
1239
|
|
|
for ($y = 0; $y < ($src_y); $y++) |
1240
|
|
|
{ |
1241
|
|
|
for ($x = 0; $x < ($src_x); $x++) |
1242
|
|
|
{ |
1243
|
|
|
$color = imagecolorat($src_img, $x, $y); |
1244
|
|
|
imagesetpixel($rotate, $y, $dest_y - $x - 1, $color); |
1245
|
|
|
} |
1246
|
|
|
} |
1247
|
|
|
break; |
1248
|
|
|
case 180: |
1249
|
|
|
for ($y = 0; $y < ($src_y); $y++) |
1250
|
|
|
{ |
1251
|
|
|
for ($x = 0; $x < ($src_x); $x++) |
1252
|
|
|
{ |
1253
|
|
|
$color = imagecolorat($src_img, $x, $y); |
1254
|
|
|
imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1, $color); |
1255
|
|
|
} |
1256
|
|
|
} |
1257
|
|
|
break; |
1258
|
|
|
default: $rotate = $src_img; |
1259
|
|
|
}; |
1260
|
|
|
return $rotate;*/ |
1261
|
|
|
} |
1262
|
|
|
} |
1263
|
|
|
?> |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.