00001 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 if ( ! function_exists('read_file'))
00040 {
00041 function read_file($file)
00042 {
00043 if ( ! file_exists($file))
00044 {
00045 return FALSE;
00046 }
00047
00048 if (function_exists('file_get_contents'))
00049 {
00050 return file_get_contents($file);
00051 }
00052
00053 if ( ! $fp = @fopen($file, FOPEN_READ))
00054 {
00055 return FALSE;
00056 }
00057
00058 flock($fp, LOCK_SH);
00059
00060 $data = '';
00061 if (filesize($file) > 0)
00062 {
00063 $data =& fread($fp, filesize($file));
00064 }
00065
00066 flock($fp, LOCK_UN);
00067 fclose($fp);
00068
00069 return $data;
00070 }
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 if ( ! function_exists('write_file'))
00087 {
00088 function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE)
00089 {
00090 if ( ! $fp = @fopen($path, $mode))
00091 {
00092 return FALSE;
00093 }
00094
00095 flock($fp, LOCK_EX);
00096 fwrite($fp, $data);
00097 flock($fp, LOCK_UN);
00098 fclose($fp);
00099
00100 return TRUE;
00101 }
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 if ( ! function_exists('delete_files'))
00120 {
00121 function delete_files($path, $del_dir = FALSE, $level = 0)
00122 {
00123
00124 $path = preg_replace("|^(.+?)/*$|", "\\1", $path);
00125
00126 if ( ! $current_dir = @opendir($path))
00127 return;
00128
00129 while(FALSE !== ($filename = @readdir($current_dir)))
00130 {
00131 if ($filename != "." and $filename != "..")
00132 {
00133 if (is_dir($path.'/'.$filename))
00134 {
00135 delete_files($path.'/'.$filename, $del_dir, $level + 1);
00136 }
00137 else
00138 {
00139 unlink($path.'/'.$filename);
00140 }
00141 }
00142 }
00143 @closedir($current_dir);
00144
00145 if ($del_dir == TRUE AND $level > 0)
00146 {
00147 @rmdir($path);
00148 }
00149 }
00150 }
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 if ( ! function_exists('get_filenames'))
00167 {
00168 function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE)
00169 {
00170 static $_filedata = array();
00171
00172 if ($fp = @opendir($source_dir))
00173 {
00174
00175 if ($_recursion === FALSE)
00176 {
00177 $_filedata = array();
00178 $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
00179 }
00180
00181 while (FALSE !== ($file = readdir($fp)))
00182 {
00183 if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)
00184 {
00185 get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
00186 }
00187 elseif (strncmp($file, '.', 1) !== 0)
00188 {
00189
00190 $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file;
00191 }
00192 }
00193 return $_filedata;
00194 }
00195 else
00196 {
00197 return FALSE;
00198 }
00199 }
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 if ( ! function_exists('get_dir_file_info'))
00219 {
00220 function get_dir_file_info($source_dir, $include_path = FALSE, $_recursion = FALSE)
00221 {
00222 $_filedata = array();
00223 $relative_path = $source_dir;
00224
00225 if ($fp = @opendir($source_dir))
00226 {
00227
00228 if ($_recursion === FALSE)
00229 {
00230 $_filedata = array();
00231 $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
00232 }
00233
00234 while (FALSE !== ($file = readdir($fp)))
00235 {
00236 if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)
00237 {
00238 get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
00239 }
00240 elseif (strncmp($file, '.', 1) !== 0)
00241 {
00242 $_filedata[$file] = get_file_info($source_dir.$file);
00243 $_filedata[$file]['relative_path'] = $relative_path;
00244 }
00245 }
00246 return $_filedata;
00247 }
00248 else
00249 {
00250 return FALSE;
00251 }
00252 }
00253 }
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 if ( ! function_exists('get_file_info'))
00271 {
00272 function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date'))
00273 {
00274
00275 if ( ! file_exists($file))
00276 {
00277 return FALSE;
00278 }
00279
00280 if (is_string($returned_values))
00281 {
00282 $returned_values = explode(',', $returned_values);
00283 }
00284
00285 foreach ($returned_values as $key)
00286 {
00287 switch ($key)
00288 {
00289 case 'name':
00290 $fileinfo['name'] = substr(strrchr($file, '/'), 1);
00291 break;
00292 case 'server_path':
00293 $fileinfo['server_path'] = $file;
00294 break;
00295 case 'size':
00296 $fileinfo['size'] = filesize($file);
00297 break;
00298 case 'date':
00299 $fileinfo['date'] = filectime($file);
00300 break;
00301 case 'readable':
00302 $fileinfo['readable'] = is_readable($file);
00303 break;
00304 case 'writable':
00305
00306 $fileinfo['writable'] = is_writable($file);
00307 break;
00308 case 'executable':
00309 $fileinfo['executable'] = is_executable($file);
00310 break;
00311 case 'fileperms':
00312 $fileinfo['fileperms'] = fileperms($file);
00313 break;
00314 }
00315 }
00316
00317 return $fileinfo;
00318 }
00319 }
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336 if ( ! function_exists('get_mime_by_extension'))
00337 {
00338 function get_mime_by_extension($file)
00339 {
00340 $extension = substr(strrchr($file, '.'), 1);
00341
00342 global $mimes;
00343
00344 if ( ! is_array($mimes))
00345 {
00346 if ( ! require_once(APPPATH.'config/mimes.php'))
00347 {
00348 return FALSE;
00349 }
00350 }
00351
00352 if (array_key_exists($extension, $mimes))
00353 {
00354 if (is_array($mimes[$extension]))
00355 {
00356
00357 return current($mimes[$extension]);
00358 }
00359 else
00360 {
00361 return $mimes[$extension];
00362 }
00363 }
00364 else
00365 {
00366 return FALSE;
00367 }
00368 }
00369 }
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383 if ( ! function_exists('symbolic_permissions'))
00384 {
00385 function symbolic_permissions($perms)
00386 {
00387 if (($perms & 0xC000) == 0xC000)
00388 {
00389 $symbolic = 's';
00390 }
00391 elseif (($perms & 0xA000) == 0xA000)
00392 {
00393 $symbolic = 'l';
00394 }
00395 elseif (($perms & 0x8000) == 0x8000)
00396 {
00397 $symbolic = '-';
00398 }
00399 elseif (($perms & 0x6000) == 0x6000)
00400 {
00401 $symbolic = 'b';
00402 }
00403 elseif (($perms & 0x4000) == 0x4000)
00404 {
00405 $symbolic = 'd';
00406 }
00407 elseif (($perms & 0x2000) == 0x2000)
00408 {
00409 $symbolic = 'c';
00410 }
00411 elseif (($perms & 0x1000) == 0x1000)
00412 {
00413 $symbolic = 'p';
00414 }
00415 else
00416 {
00417 $symbolic = 'u';
00418 }
00419
00420
00421 $symbolic .= (($perms & 0x0100) ? 'r' : '-');
00422 $symbolic .= (($perms & 0x0080) ? 'w' : '-');
00423 $symbolic .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
00424
00425
00426 $symbolic .= (($perms & 0x0020) ? 'r' : '-');
00427 $symbolic .= (($perms & 0x0010) ? 'w' : '-');
00428 $symbolic .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
00429
00430
00431 $symbolic .= (($perms & 0x0004) ? 'r' : '-');
00432 $symbolic .= (($perms & 0x0002) ? 'w' : '-');
00433 $symbolic .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
00434
00435 return $symbolic;
00436 }
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 if ( ! function_exists('octal_permissions'))
00452 {
00453 function octal_permissions($perms)
00454 {
00455 return substr(sprintf('%o', $perms), -3);
00456 }
00457 }
00458
00459
00460
00461