Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
| 19 | * CodeIgniter File Helpers
|
| 20 | *
|
| 21 | * @package CodeIgniter
|
| 22 | * @subpackage Helpers
|
| 23 | * @category Helpers
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 24 | * @author ExpressionEngine Dev Team
|
Derek Jones | fd93d22 | 2008-05-06 15:18:50 +0000 | [diff] [blame] | 25 | * @link http://codeigniter.com/user_guide/helpers/file_helper.html
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 26 | */
|
| 27 |
|
| 28 | // ------------------------------------------------------------------------
|
| 29 |
|
| 30 | /**
|
| 31 | * Read File
|
| 32 | *
|
| 33 | * Opens the file specfied in the path and returns it as a string.
|
| 34 | *
|
| 35 | * @access public
|
| 36 | * @param string path to file
|
| 37 | * @return string
|
| 38 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 39 | if ( ! function_exists('read_file'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 40 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 41 | function read_file($file)
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 42 | {
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 43 | if ( ! file_exists($file))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 44 | {
|
| 45 | return FALSE;
|
| 46 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 47 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 48 | if (function_exists('file_get_contents'))
|
| 49 | {
|
| 50 | return file_get_contents($file);
|
| 51 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 52 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 53 | if ( ! $fp = @fopen($file, FOPEN_READ))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 54 | {
|
| 55 | return FALSE;
|
| 56 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 57 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 58 | flock($fp, LOCK_SH);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 59 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 60 | $data = '';
|
| 61 | if (filesize($file) > 0)
|
| 62 | {
|
| 63 | $data =& fread($fp, filesize($file));
|
| 64 | }
|
| 65 |
|
| 66 | flock($fp, LOCK_UN);
|
| 67 | fclose($fp);
|
| 68 |
|
| 69 | return $data;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 70 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 71 | }
|
| 72 |
|
| 73 | // ------------------------------------------------------------------------
|
| 74 |
|
| 75 | /**
|
| 76 | * Write File
|
| 77 | *
|
| 78 | * Writes data to the file specified in the path.
|
| 79 | * Creates a new file if non-existent.
|
| 80 | *
|
| 81 | * @access public
|
| 82 | * @param string path to file
|
| 83 | * @param string file data
|
| 84 | * @return bool
|
| 85 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 86 | if ( ! function_exists('write_file'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 87 | {
|
Derek Jones | 3be20e2 | 2008-05-05 20:07:09 +0000 | [diff] [blame] | 88 | function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE)
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 89 | {
|
Derek Jones | 9e11220 | 2008-05-28 23:46:28 +0000 | [diff] [blame] | 90 | if ( ! $fp = @fopen($path, $mode))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 91 | {
|
| 92 | return FALSE;
|
| 93 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 94 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 95 | flock($fp, LOCK_EX);
|
| 96 | fwrite($fp, $data);
|
| 97 | flock($fp, LOCK_UN);
|
| 98 | fclose($fp);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 99 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 100 | return TRUE;
|
| 101 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 102 | }
|
| 103 |
|
| 104 | // ------------------------------------------------------------------------
|
| 105 |
|
| 106 | /**
|
| 107 | * Delete Files
|
| 108 | *
|
| 109 | * Deletes all files contained in the supplied directory path.
|
| 110 | * Files must be writable or owned by the system in order to be deleted.
|
| 111 | * If the second parameter is set to TRUE, any directories contained
|
| 112 | * within the supplied base directory will be nuked as well.
|
| 113 | *
|
| 114 | * @access public
|
| 115 | * @param string path to file
|
| 116 | * @param bool whether to delete any directories found in the path
|
| 117 | * @return bool
|
| 118 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 119 | if ( ! function_exists('delete_files'))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 120 | {
|
| 121 | function delete_files($path, $del_dir = FALSE, $level = 0)
|
| 122 | {
|
| 123 | // Trim the trailing slash
|
| 124 | $path = preg_replace("|^(.+?)/*$|", "\\1", $path);
|
Derek Jones | 1c8dd3a | 2008-01-29 20:20:00 +0000 | [diff] [blame] | 125 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 126 | if ( ! $current_dir = @opendir($path))
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 127 | return;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 128 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 129 | while(FALSE !== ($filename = @readdir($current_dir)))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 130 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 131 | if ($filename != "." and $filename != "..")
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 132 | {
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 133 | if (is_dir($path.'/'.$filename))
|
| 134 | {
|
Derek Jones | 1c8dd3a | 2008-01-29 20:20:00 +0000 | [diff] [blame] | 135 | delete_files($path.'/'.$filename, $del_dir, $level + 1);
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 136 | }
|
| 137 | else
|
| 138 | {
|
| 139 | unlink($path.'/'.$filename);
|
| 140 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 141 | }
|
| 142 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 143 | @closedir($current_dir);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 144 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 145 | if ($del_dir == TRUE AND $level > 0)
|
| 146 | {
|
| 147 | @rmdir($path);
|
| 148 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 149 | }
|
| 150 | }
|
| 151 |
|
| 152 | // ------------------------------------------------------------------------
|
| 153 |
|
| 154 | /**
|
| 155 | * Get Filenames
|
| 156 | *
|
| 157 | * Reads the specified directory and builds an array containing the filenames.
|
| 158 | * Any sub-folders contained within the specified path are read as well.
|
| 159 | *
|
| 160 | * @access public
|
| 161 | * @param string path to source
|
| 162 | * @param bool whether to include the path as part of the filename
|
Derek Jones | 560efb3 | 2008-03-27 16:07:00 +0000 | [diff] [blame] | 163 | * @param bool internal variable to determine recursion status - do not use in calls
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 164 | * @return array
|
| 165 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 166 | if ( ! function_exists('get_filenames'))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 167 | {
|
Derek Jones | 560efb3 | 2008-03-27 16:07:00 +0000 | [diff] [blame] | 168 | function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE)
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 169 | {
|
Derek Jones | 14031d1 | 2008-05-05 18:29:43 +0000 | [diff] [blame] | 170 | static $_filedata = array();
|
Derek Jones | f00992d | 2008-03-28 14:13:14 +0000 | [diff] [blame] | 171 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 172 | if ($fp = @opendir($source_dir))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 173 | {
|
Derek Jones | f00992d | 2008-03-28 14:13:14 +0000 | [diff] [blame] | 174 | // reset the array and make sure $source_dir has a trailing slash on the initial call
|
| 175 | if ($_recursion === FALSE)
|
| 176 | {
|
| 177 | $_filedata = array();
|
Derek Jones | ac7c81e | 2008-04-01 13:59:49 +0000 | [diff] [blame] | 178 | $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
|
Derek Jones | f00992d | 2008-03-28 14:13:14 +0000 | [diff] [blame] | 179 | }
|
| 180 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 181 | while (FALSE !== ($file = readdir($fp)))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 182 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 183 | if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 184 | {
|
Derek Jones | ac7c81e | 2008-04-01 13:59:49 +0000 | [diff] [blame] | 185 | get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 186 | }
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 187 | elseif (strncmp($file, '.', 1) !== 0)
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 188 | {
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 189 |
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 190 | $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file;
|
| 191 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 192 | }
|
Derek Jones | 269b942 | 2008-01-28 21:00:20 +0000 | [diff] [blame] | 193 | return $_filedata;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 194 | }
|
Derek Jones | fd97178 | 2008-02-20 18:39:18 +0000 | [diff] [blame] | 195 | else
|
| 196 | {
|
Derek Allard | bca400f | 2008-02-21 22:19:55 +0000 | [diff] [blame] | 197 | return FALSE;
|
Derek Jones | fd97178 | 2008-02-20 18:39:18 +0000 | [diff] [blame] | 198 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 199 | }
|
| 200 | }
|
| 201 |
|
Derek Allard | e4e603b | 2008-01-09 14:18:14 +0000 | [diff] [blame] | 202 | // --------------------------------------------------------------------
|
| 203 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 204 | /**
|
| 205 | * Get Directory File Information
|
| 206 | *
|
| 207 | * Reads the specified directory and builds an array containing the filenames,
|
| 208 | * filesize, dates, and permissions
|
| 209 | *
|
| 210 | * Any sub-folders contained within the specified path are read as well.
|
| 211 | *
|
| 212 | * @access public
|
| 213 | * @param string path to source
|
| 214 | * @param bool whether to include the path as part of the filename
|
| 215 | * @param bool internal variable to determine recursion status - do not use in calls
|
| 216 | * @return array
|
| 217 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 218 | if ( ! function_exists('get_dir_file_info'))
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 219 | {
|
| 220 | function get_dir_file_info($source_dir, $include_path = FALSE, $_recursion = FALSE)
|
| 221 | {
|
| 222 | $_filedata = array();
|
| 223 | $relative_path = $source_dir;
|
| 224 |
|
| 225 | if ($fp = @opendir($source_dir))
|
| 226 | {
|
| 227 | // reset the array and make sure $source_dir has a trailing slash on the initial call
|
| 228 | if ($_recursion === FALSE)
|
| 229 | {
|
| 230 | $_filedata = array();
|
| 231 | $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
|
| 232 | }
|
| 233 |
|
| 234 | while (FALSE !== ($file = readdir($fp)))
|
| 235 | {
|
| 236 | if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)
|
| 237 | {
|
| 238 | get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
|
| 239 | }
|
| 240 | elseif (strncmp($file, '.', 1) !== 0)
|
| 241 | {
|
| 242 | $_filedata[$file] = get_file_info($source_dir.$file);
|
| 243 | $_filedata[$file]['relative_path'] = $relative_path;
|
| 244 | }
|
| 245 | }
|
| 246 | return $_filedata;
|
| 247 | }
|
| 248 | else
|
| 249 | {
|
| 250 | return FALSE;
|
| 251 | }
|
| 252 | }
|
| 253 | }
|
| 254 |
|
| 255 | // --------------------------------------------------------------------
|
| 256 |
|
| 257 | /**
|
| 258 | * Get File Info
|
| 259 | *
|
| 260 | * Given a file and path, returns the name, path, size, date modified
|
| 261 | * Second parameter allows you to explicitly declare what information you want returned
|
| 262 | * Options are: name, server_path, size, date, readable, writable, executable, fileperms
|
| 263 | * Returns FALSE if the file cannot be found.
|
| 264 | *
|
Derek Allard | 993925b | 2008-08-21 12:43:31 +0000 | [diff] [blame^] | 265 | * @access public
|
| 266 | * @param string path to file
|
| 267 | * @param mixed array or comma separated string of information returned
|
| 268 | * @return array
|
| 269 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 270 | if ( ! function_exists('get_file_info'))
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 271 | {
|
Derek Allard | 993925b | 2008-08-21 12:43:31 +0000 | [diff] [blame^] | 272 | function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date'))
|
| 273 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 274 |
|
Derek Allard | 993925b | 2008-08-21 12:43:31 +0000 | [diff] [blame^] | 275 | if ( ! file_exists($file))
|
| 276 | {
|
| 277 | return FALSE;
|
| 278 | }
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 279 |
|
Derek Allard | 993925b | 2008-08-21 12:43:31 +0000 | [diff] [blame^] | 280 | if (is_string($returned_values))
|
| 281 | {
|
| 282 | $returned_values = explode(',', $returned_values);
|
| 283 | }
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 284 |
|
Derek Allard | 993925b | 2008-08-21 12:43:31 +0000 | [diff] [blame^] | 285 | foreach ($returned_values as $key)
|
| 286 | {
|
| 287 | switch ($key)
|
| 288 | {
|
| 289 | case 'name':
|
| 290 | $fileinfo['name'] = substr(strrchr($file, '/'), 1);
|
| 291 | break;
|
| 292 | case 'server_path':
|
| 293 | $fileinfo['server_path'] = $file;
|
| 294 | break;
|
| 295 | case 'size':
|
| 296 | $fileinfo['size'] = filesize($file);
|
| 297 | break;
|
| 298 | case 'date':
|
| 299 | $fileinfo['date'] = filectime($file);
|
| 300 | break;
|
| 301 | case 'readable':
|
| 302 | $fileinfo['readable'] = is_readable($file);
|
| 303 | break;
|
| 304 | case 'writable':
|
| 305 | // There are known problems using is_weritable on IIS. It may not be reliable - consider fileperms()
|
| 306 | $fileinfo['writable'] = is_writable($file);
|
| 307 | break;
|
| 308 | case 'executable':
|
| 309 | $fileinfo['executable'] = is_executable($file);
|
| 310 | break;
|
| 311 | case 'fileperms':
|
| 312 | $fileinfo['fileperms'] = fileperms($file);
|
| 313 | break;
|
| 314 | }
|
| 315 | }
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 316 |
|
Derek Allard | 993925b | 2008-08-21 12:43:31 +0000 | [diff] [blame^] | 317 | return $fileinfo;
|
| 318 | }
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 319 | }
|
| 320 |
|
| 321 | // --------------------------------------------------------------------
|
| 322 |
|
| 323 | /**
|
| 324 | * Get Mime by Extension
|
| 325 | *
|
| 326 | * Translates a file extension into a mime type based on config/mimes.php.
|
| 327 | * Returns FALSE if it can't determine the type, or open the mime config file
|
| 328 | *
|
| 329 | * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience
|
| 330 | * It should NOT be trusted, and should certainly NOT be used for security
|
| 331 | *
|
| 332 | * @access public
|
| 333 | * @param string path to file
|
| 334 | * @return mixed
|
| 335 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 336 | if ( ! function_exists('get_mime_by_extension'))
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 337 | {
|
| 338 | function get_mime_by_extension($file)
|
| 339 | {
|
| 340 | $extension = substr(strrchr($file, '.'), 1);
|
| 341 |
|
| 342 | global $mimes;
|
| 343 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 344 | if ( ! is_array($mimes))
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 345 | {
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 346 | if ( ! require_once(APPPATH.'config/mimes.php'))
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 347 | {
|
| 348 | return FALSE;
|
| 349 | }
|
| 350 | }
|
| 351 |
|
| 352 | if (array_key_exists($extension, $mimes))
|
| 353 | {
|
| 354 | if (is_array($mimes[$extension]))
|
| 355 | {
|
| 356 | // Multiple mime types, just give the first one
|
| 357 | return current($mimes[$extension]);
|
| 358 | }
|
| 359 | else
|
| 360 | {
|
| 361 | return $mimes[$extension];
|
| 362 | }
|
| 363 | }
|
| 364 | else
|
| 365 | {
|
| 366 | return FALSE;
|
| 367 | }
|
| 368 | }
|
| 369 | }
|
| 370 |
|
Derek Jones | 94a2182 | 2008-05-08 15:00:28 +0000 | [diff] [blame] | 371 | // --------------------------------------------------------------------
|
| 372 |
|
| 373 | /**
|
| 374 | * Symbolic Permissions
|
| 375 | *
|
| 376 | * Takes a numeric value representing a file's permissions and returns
|
| 377 | * standard symbolic notation representing that value
|
| 378 | *
|
| 379 | * @access public
|
| 380 | * @param int
|
| 381 | * @return string
|
| 382 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 383 | if ( ! function_exists('symbolic_permissions'))
|
Derek Jones | 94a2182 | 2008-05-08 15:00:28 +0000 | [diff] [blame] | 384 | {
|
| 385 | function symbolic_permissions($perms)
|
| 386 | {
|
| 387 | if (($perms & 0xC000) == 0xC000)
|
| 388 | {
|
| 389 | $symbolic = 's'; // Socket
|
| 390 | }
|
| 391 | elseif (($perms & 0xA000) == 0xA000)
|
| 392 | {
|
| 393 | $symbolic = 'l'; // Symbolic Link
|
| 394 | }
|
| 395 | elseif (($perms & 0x8000) == 0x8000)
|
| 396 | {
|
| 397 | $symbolic = '-'; // Regular
|
| 398 | }
|
| 399 | elseif (($perms & 0x6000) == 0x6000)
|
| 400 | {
|
| 401 | $symbolic = 'b'; // Block special
|
| 402 | }
|
| 403 | elseif (($perms & 0x4000) == 0x4000)
|
| 404 | {
|
| 405 | $symbolic = 'd'; // Directory
|
| 406 | }
|
| 407 | elseif (($perms & 0x2000) == 0x2000)
|
| 408 | {
|
| 409 | $symbolic = 'c'; // Character special
|
| 410 | }
|
| 411 | elseif (($perms & 0x1000) == 0x1000)
|
| 412 | {
|
| 413 | $symbolic = 'p'; // FIFO pipe
|
| 414 | }
|
| 415 | else
|
| 416 | {
|
| 417 | $symbolic = 'u'; // Unknown
|
| 418 | }
|
| 419 |
|
| 420 | // Owner
|
| 421 | $symbolic .= (($perms & 0x0100) ? 'r' : '-');
|
| 422 | $symbolic .= (($perms & 0x0080) ? 'w' : '-');
|
| 423 | $symbolic .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
|
| 424 |
|
| 425 | // Group
|
| 426 | $symbolic .= (($perms & 0x0020) ? 'r' : '-');
|
| 427 | $symbolic .= (($perms & 0x0010) ? 'w' : '-');
|
| 428 | $symbolic .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
|
| 429 |
|
| 430 | // World
|
| 431 | $symbolic .= (($perms & 0x0004) ? 'r' : '-');
|
| 432 | $symbolic .= (($perms & 0x0002) ? 'w' : '-');
|
| 433 | $symbolic .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
|
| 434 |
|
| 435 | return $symbolic;
|
| 436 | }
|
| 437 | }
|
| 438 |
|
| 439 | // --------------------------------------------------------------------
|
| 440 |
|
| 441 | /**
|
| 442 | * Octal Permissions
|
| 443 | *
|
| 444 | * Takes a numeric value representing a file's permissions and returns
|
| 445 | * a three character string representing the file's octal permissions
|
| 446 | *
|
| 447 | * @access public
|
| 448 | * @param int
|
| 449 | * @return string
|
| 450 | */
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 451 | if ( ! function_exists('octal_permissions'))
|
Derek Jones | 94a2182 | 2008-05-08 15:00:28 +0000 | [diff] [blame] | 452 | {
|
| 453 | function octal_permissions($perms)
|
| 454 | {
|
| 455 | return substr(sprintf('%o', $perms), -3);
|
| 456 | }
|
| 457 | }
|
| 458 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 459 |
|
| 460 | /* End of file file_helper.php */
|
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 461 | /* Location: ./system/helpers/file_helper.php */ |