1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
if($_SESSION["verify"] != "RESPONSIVEfilemanager") die('forbiden'); |
4
|
|
|
|
5
|
|
|
function deleteDir($dir) { |
6
|
|
|
if (!file_exists($dir)) return true; |
7
|
|
|
if (!is_dir($dir)) return unlink($dir); |
8
|
|
|
foreach (scandir($dir) as $item) { |
9
|
|
|
if ($item == '.' || $item == '..') continue; |
10
|
|
|
if (!deleteDir($dir.DIRECTORY_SEPARATOR.$item)) return false; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
return rmdir($dir); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
function duplicate_file($old_path,$name){ |
17
|
|
View Code Duplication |
if(file_exists($old_path)){ |
|
|
|
|
18
|
|
|
$info=pathinfo($old_path); |
19
|
|
|
$new_path=$info['dirname']."/".$name.".".$info['extension']; |
20
|
|
|
if(file_exists($new_path)) return false; |
21
|
|
|
|
22
|
|
|
return copy($old_path,$new_path); |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
function rename_file($old_path,$name,$transliteration){ |
27
|
|
|
$name=fix_filename($name,$transliteration); |
28
|
|
View Code Duplication |
if(file_exists($old_path)){ |
|
|
|
|
29
|
|
|
$info=pathinfo($old_path); |
30
|
|
|
$new_path=$info['dirname']."/".$name.".".$info['extension']; |
31
|
|
|
if(file_exists($new_path)) return false; |
32
|
|
|
|
33
|
|
|
return rename($old_path,$new_path); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function rename_folder($old_path,$name,$transliteration){ |
38
|
|
|
$name=fix_filename($name,$transliteration); |
39
|
|
|
if(file_exists($old_path)){ |
40
|
|
|
$new_path=fix_dirname($old_path)."/".$name; |
41
|
|
|
if(file_exists($new_path)) return false; |
42
|
|
|
|
43
|
|
|
return rename($old_path,$new_path); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
function create_img_gd($imgfile, $imgthumb, $newwidth, $newheight="") { |
|
|
|
|
48
|
|
|
if(image_check_memory_usage($imgfile,$newwidth,$newheight)){ |
49
|
|
|
require_once('php_image_magician.php'); |
50
|
|
|
$magicianObj = new imageLib($imgfile); |
51
|
|
|
$magicianObj -> resizeImage($newwidth, $newheight, 'crop'); |
52
|
|
|
$magicianObj -> saveImage($imgthumb,80); |
53
|
|
|
|
54
|
|
|
return true; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return false; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
function create_img($imgfile, $imgthumb, $newwidth, $newheight="") { |
|
|
|
|
61
|
|
|
if(image_check_memory_usage($imgfile,$newwidth,$newheight)){ |
62
|
|
|
require_once('php_image_magician.php'); |
63
|
|
|
$magicianObj = new imageLib($imgfile); |
64
|
|
|
$magicianObj -> resizeImage($newwidth, $newheight, 'auto'); |
65
|
|
|
$magicianObj -> saveImage($imgthumb,80); |
66
|
|
|
|
67
|
|
|
return true; |
68
|
|
|
}else{ |
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function makeSize($size) { |
74
|
|
|
$units = array('B','KB','MB','GB','TB'); |
75
|
|
|
$u = 0; |
76
|
|
|
while ( (round($size / 1024) > 0) && ($u < 4) ) { |
77
|
|
|
$size = $size / 1024; |
78
|
|
|
++$u; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return (number_format($size, 0) . " " . $units[$u]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
function foldersize($path) { |
85
|
|
|
$total_size = 0; |
86
|
|
|
$files = scandir($path); |
87
|
|
|
$cleanPath = rtrim($path, '/'). '/'; |
88
|
|
|
|
89
|
|
|
foreach($files as $t) { |
90
|
|
|
if ($t<>"." && $t<>"..") { |
91
|
|
|
$currentFile = $cleanPath . $t; |
92
|
|
|
if (is_dir($currentFile)) { |
93
|
|
|
$size = foldersize($currentFile); |
94
|
|
|
$total_size += $size; |
95
|
|
|
} |
96
|
|
|
else { |
97
|
|
|
$size = filesize($currentFile); |
98
|
|
|
$total_size += $size; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $total_size; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
function create_folder($path=false,$path_thumbs=false){ |
107
|
|
|
$oldumask = umask(0); |
108
|
|
|
if ($path && !file_exists($path)) |
109
|
|
|
mkdir($path, 0777, true); // or even 01777 so you get the sticky bit set |
110
|
|
|
if($path_thumbs && !file_exists($path_thumbs)) |
111
|
|
|
mkdir($path_thumbs, 0777, true) or die("$path_thumbs cannot be found"); // or even 01777 so you get the sticky bit set |
|
|
|
|
112
|
|
|
umask($oldumask); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
function check_files_extensions_on_path($path,$ext){ |
116
|
|
|
if(!is_dir($path)){ |
117
|
|
|
$fileinfo = pathinfo($path); |
118
|
|
|
if(!in_array(mb_strtolower($fileinfo['extension']),$ext)) |
119
|
|
|
unlink($path); |
120
|
|
|
}else{ |
121
|
|
|
$files = scandir($path); |
122
|
|
|
foreach($files as $file){ |
123
|
|
|
check_files_extensions_on_path(trim($path,'/')."/".$file,$ext); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
function check_files_extensions_on_phar( $phar, &$files, $basepath, $ext ) { |
129
|
|
|
foreach( $phar as $file ) |
130
|
|
|
{ |
131
|
|
|
if( $file->isFile() ) |
132
|
|
|
{ |
133
|
|
|
if(in_array(mb_strtolower($file->getExtension()),$ext)) |
134
|
|
|
{ |
135
|
|
|
$files[] = $basepath.$file->getFileName( ); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
else if( $file->isDir() ) |
139
|
|
|
{ |
140
|
|
|
$iterator = new DirectoryIterator( $file ); |
141
|
|
|
check_files_extensions_on_phar($iterator, $files, $basepath.$file->getFileName().'/', $ext); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
function fix_filename($str,$transliteration){ |
147
|
|
|
if($transliteration){ |
148
|
|
|
if( function_exists( 'transliterator_transliterate' ) ) |
149
|
|
|
{ |
150
|
|
|
$str = transliterator_transliterate( 'Accents-Any', $str ); |
151
|
|
|
} |
152
|
|
|
else |
153
|
|
|
{ |
154
|
|
|
$str = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$str = preg_replace( "/[^a-zA-Z0-9\.\[\]_| -]/", '', $str ); |
158
|
|
|
} |
159
|
|
|
// Empty or incorrectly transliterated filename. |
160
|
|
|
// Here is a point: a good file UNKNOWN_LANGUAGE.jpg could become .jpg in previous code. |
161
|
|
|
// So we add that default 'file' name to fix that issue. |
162
|
|
|
if( strpos( $str, '.' ) === 0 ) |
163
|
|
|
{ |
164
|
|
|
$str = 'file'.$str; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
return trim( $str ); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
function fix_dirname($str){ |
171
|
|
|
return str_replace('~',' ',dirname(str_replace(' ','~',$str))); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
function fix_strtoupper($str){ |
175
|
|
|
if( function_exists( 'mb_strtoupper' ) ) |
176
|
|
|
return mb_strtoupper($str); |
177
|
|
|
else |
178
|
|
|
return strtoupper($str); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
function fix_strtolower($str){ |
182
|
|
|
if( function_exists( 'mb_strtoupper' ) ) |
183
|
|
|
return mb_strtolower($str); |
184
|
|
|
else |
185
|
|
|
return strtolower($str); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
function fix_path($path,$transliteration){ |
189
|
|
|
$info=pathinfo($path); |
190
|
|
|
$tmp_path=$info['dirname']; |
191
|
|
|
$str=fix_filename($info['filename'],$transliteration); |
192
|
|
|
if($tmp_path!="") |
193
|
|
|
return $tmp_path.DIRECTORY_SEPARATOR.$str; |
194
|
|
|
else |
195
|
|
|
return $str; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
function base_url(){ |
|
|
|
|
199
|
|
|
return sprintf( |
200
|
|
|
"%s://%s", |
201
|
|
|
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', |
202
|
|
|
$_SERVER['HTTP_HOST'] |
203
|
|
|
); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
function config_loading($current_path,$fld){ |
207
|
|
|
if(file_exists($current_path.$fld.".config")){ |
208
|
|
|
require_once($current_path.$fld.".config"); |
209
|
|
|
|
210
|
|
|
return true; |
211
|
|
|
} |
212
|
|
|
echo "!!!!".$parent=fix_dirname($fld); |
213
|
|
|
if($parent!="." && !empty($parent)){ |
214
|
|
|
config_loading($current_path,$parent); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
return false; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
function image_check_memory_usage($img, $max_breedte, $max_hoogte){ |
221
|
|
|
if(file_exists($img)){ |
222
|
|
|
$K64 = 65536; // number of bytes in 64K |
223
|
|
|
$memory_usage = memory_get_usage(); |
224
|
|
|
$memory_limit = abs(intval(str_replace('M','',ini_get('memory_limit'))*1024*1024)); |
225
|
|
|
$image_properties = getimagesize($img); |
226
|
|
|
$image_width = $image_properties[0]; |
227
|
|
|
$image_height = $image_properties[1]; |
228
|
|
|
$image_bits = $image_properties['bits']; |
229
|
|
|
$image_memory_usage = $K64 + ($image_width * $image_height * ($image_bits ) * 2); |
230
|
|
|
$thumb_memory_usage = $K64 + ($max_breedte * $max_hoogte * ($image_bits ) * 2); |
231
|
|
|
$memory_needed = intval($memory_usage + $image_memory_usage + $thumb_memory_usage); |
232
|
|
|
|
233
|
|
|
if($memory_needed > $memory_limit){ |
234
|
|
|
ini_set('memory_limit',(intval($memory_needed/1024/1024)+5) . 'M'); |
235
|
|
|
if(ini_get('memory_limit') == (intval($memory_needed/1024/1024)+5) . 'M'){ |
236
|
|
|
return true; |
237
|
|
|
}else{ |
238
|
|
|
return false; |
239
|
|
|
} |
240
|
|
|
}else{ |
241
|
|
|
return true; |
242
|
|
|
} |
243
|
|
|
}else{ |
244
|
|
|
return false; |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
function endsWith($haystack, $needle) |
249
|
|
|
{ |
250
|
|
|
return $needle === "" || substr($haystack, -strlen($needle)) === $needle; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
function new_thumbnails_creation($targetPath,$targetFile,$name,$current_path,$relative_image_creation,$relative_path_from_current_pos,$relative_image_creation_name_to_prepend,$relative_image_creation_name_to_append,$relative_image_creation_width,$relative_image_creation_height,$fixed_image_creation,$fixed_path_from_filemanager,$fixed_image_creation_name_to_prepend,$fixed_image_creation_to_append,$fixed_image_creation_width,$fixed_image_creation_height){ |
254
|
|
|
//create relative thumbs |
255
|
|
|
$all_ok=true; |
256
|
|
|
if($relative_image_creation){ |
257
|
|
|
foreach($relative_path_from_current_pos as $k=>$path){ |
258
|
|
View Code Duplication |
if($path!="" && $path[strlen($path)-1]!="/") $path.="/"; |
|
|
|
|
259
|
|
|
if (!file_exists($targetPath.$path)) create_folder($targetPath.$path,false); |
|
|
|
|
260
|
|
|
$info=pathinfo($name); |
261
|
|
View Code Duplication |
if(!endsWith($targetPath,$path)) |
|
|
|
|
262
|
|
|
if(!create_img($targetFile, $targetPath.$path.$relative_image_creation_name_to_prepend[$k].$info['filename'].$relative_image_creation_name_to_append[$k].".".$info['extension'], $relative_image_creation_width[$k], $relative_image_creation_height[$k])) |
263
|
|
|
$all_ok=false; |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
//create fixed thumbs |
268
|
|
|
if($fixed_image_creation){ |
269
|
|
|
foreach($fixed_path_from_filemanager as $k=>$path){ |
270
|
|
View Code Duplication |
if($path!="" && $path[strlen($path)-1]!="/") $path.="/"; |
|
|
|
|
271
|
|
|
$base_dir=$path.substr_replace($targetPath, '', 0, strlen($current_path)); |
272
|
|
|
if (!file_exists($base_dir)) create_folder($base_dir,false); |
|
|
|
|
273
|
|
|
$info=pathinfo($name); |
274
|
|
View Code Duplication |
if(!create_img($targetFile, $base_dir.$fixed_image_creation_name_to_prepend[$k].$info['filename'].$fixed_image_creation_to_append[$k].".".$info['extension'], $fixed_image_creation_width[$k], $fixed_image_creation_height[$k])) |
|
|
|
|
275
|
|
|
$all_ok=false; |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
return $all_ok; |
280
|
|
|
} |
281
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.