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
00136 if (substr($filename, 0, 1) != '.')
00137 {
00138 delete_files($path.'/'.$filename, $del_dir, $level + 1);
00139 }
00140 }
00141 else
00142 {
00143 unlink($path.'/'.$filename);
00144 }
00145 }
00146 }
00147 @closedir($current_dir);
00148
00149 if ($del_dir == TRUE AND $level > 0)
00150 {
00151 @rmdir($path);
00152 }
00153 }
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 if ( ! function_exists('get_filenames'))
00171 {
00172 function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE)
00173 {
00174 static $_filedata = array();
00175
00176 if ($fp = @opendir($source_dir))
00177 {
00178
00179 if ($_recursion === FALSE)
00180 {
00181 $_filedata = array();
00182 $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
00183 }
00184
00185 while (FALSE !== ($file = readdir($fp)))
00186 {
00187 if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)
00188 {
00189 get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
00190 }
00191 elseif (strncmp($file, '.', 1) !== 0)
00192 {
00193
00194 $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file;
00195 }
00196 }
00197 return $_filedata;
00198 }
00199 else
00200 {
00201 return FALSE;
00202 }
00203 }
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 if ( ! function_exists('get_dir_file_info'))
00223 {
00224 function get_dir_file_info($source_dir, $include_path = FALSE, $_recursion = FALSE)
00225 {
00226 $_filedata = array();
00227 $relative_path = $source_dir;
00228
00229 if ($fp = @opendir($source_dir))
00230 {
00231
00232 if ($_recursion === FALSE)
00233 {
00234 $_filedata = array();
00235 $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
00236 }
00237
00238 while (FALSE !== ($file = readdir($fp)))
00239 {
00240 if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)
00241 {
00242 get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
00243 }
00244 elseif (strncmp($file, '.', 1) !== 0)
00245 {
00246 $_filedata[$file] = get_file_info($source_dir.$file);
00247 $_filedata[$file]['relative_path'] = $relative_path;
00248 }
00249 }
00250 return $_filedata;
00251 }
00252 else
00253 {
00254 return FALSE;
00255 }
00256 }
00257 }
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 if ( ! function_exists('get_file_info'))
00275 {
00276 function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date'))
00277 {
00278
00279 if ( ! file_exists($file))
00280 {
00281 return FALSE;
00282 }
00283
00284 if (is_string($returned_values))
00285 {
00286 $returned_values = explode(',', $returned_values);
00287 }
00288
00289 foreach ($returned_values as $key)
00290 {
00291 switch ($key)
00292 {
00293 case 'name':
00294 $fileinfo['name'] = substr(strrchr($file, '/'), 1);
00295 break;
00296 case 'server_path':
00297 $fileinfo['server_path'] = $file;
00298 break;
00299 case 'size':
00300 $fileinfo['size'] = filesize($file);
00301 break;
00302 case 'date':
00303 $fileinfo['date'] = filectime($file);
00304 break;
00305 case 'readable':
00306 $fileinfo['readable'] = is_readable($file);
00307 break;
00308 case 'writable':
00309
00310 $fileinfo['writable'] = is_writable($file);
00311 break;
00312 case 'executable':
00313 $fileinfo['executable'] = is_executable($file);
00314 break;
00315 case 'fileperms':
00316 $fileinfo['fileperms'] = fileperms($file);
00317 break;
00318 }
00319 }
00320
00321 return $fileinfo;
00322 }
00323 }
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 if ( ! function_exists('get_mime_by_extension'))
00341 {
00342 function get_mime_by_extension($file)
00343 {
00344 $extension = substr(strrchr($file, '.'), 1);
00345
00346 global $mimes;
00347
00348 if ( ! is_array($mimes))
00349 {
00350 if ( ! require_once(APPPATH.'config/mimes.php'))
00351 {
00352 return FALSE;
00353 }
00354 }
00355
00356 if (array_key_exists($extension, $mimes))
00357 {
00358 if (is_array($mimes[$extension]))
00359 {
00360
00361 return current($mimes[$extension]);
00362 }
00363 else
00364 {
00365 return $mimes[$extension];
00366 }
00367 }
00368 else
00369 {
00370 return FALSE;
00371 }
00372 }
00373 }
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387 if ( ! function_exists('symbolic_permissions'))
00388 {
00389 function symbolic_permissions($perms)
00390 {
00391 if (($perms & 0xC000) == 0xC000)
00392 {
00393 $symbolic = 's';
00394 }
00395 elseif (($perms & 0xA000) == 0xA000)
00396 {
00397 $symbolic = 'l';
00398 }
00399 elseif (($perms & 0x8000) == 0x8000)
00400 {
00401 $symbolic = '-';
00402 }
00403 elseif (($perms & 0x6000) == 0x6000)
00404 {
00405 $symbolic = 'b';
00406 }
00407 elseif (($perms & 0x4000) == 0x4000)
00408 {
00409 $symbolic = 'd';
00410 }
00411 elseif (($perms & 0x2000) == 0x2000)
00412 {
00413 $symbolic = 'c';
00414 }
00415 elseif (($perms & 0x1000) == 0x1000)
00416 {
00417 $symbolic = 'p';
00418 }
00419 else
00420 {
00421 $symbolic = 'u';
00422 }
00423
00424
00425 $symbolic .= (($perms & 0x0100) ? 'r' : '-');
00426 $symbolic .= (($perms & 0x0080) ? 'w' : '-');
00427 $symbolic .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
00428
00429
00430 $symbolic .= (($perms & 0x0020) ? 'r' : '-');
00431 $symbolic .= (($perms & 0x0010) ? 'w' : '-');
00432 $symbolic .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
00433
00434
00435 $symbolic .= (($perms & 0x0004) ? 'r' : '-');
00436 $symbolic .= (($perms & 0x0002) ? 'w' : '-');
00437 $symbolic .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
00438
00439 return $symbolic;
00440 }
00441 }
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455 if ( ! function_exists('octal_permissions'))
00456 {
00457 function octal_permissions($perms)
00458 {
00459 return substr(sprintf('%o', $perms), -3);
00460 }
00461 }
00462
00463
00464
00465