blob: 3a373efd31eecbdbc90bb706e9f8c2da938b7865 [file] [log] [blame]
Andrey Andreev8bf6bb62012-01-06 16:11:04 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev8bf6bb62012-01-06 16:11:04 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev8bf6bb62012-01-06 16:11:04 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * CodeIgniter File Helpers
30 *
31 * @package CodeIgniter
32 * @subpackage Helpers
33 * @category Helpers
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Jonesc37f0e12009-04-21 13:33:40 +000035 * @link http://codeigniter.com/user_guide/helpers/file_helpers.html
Derek Allard2067d1a2008-11-13 22:59:24 +000036 */
37
38// ------------------------------------------------------------------------
39
40/**
41 * Read File
42 *
43 * Opens the file specfied in the path and returns it as a string.
44 *
Derek Allard2067d1a2008-11-13 22:59:24 +000045 * @param string path to file
46 * @return string
Barry Mienydd671972010-10-04 16:33:58 +020047 */
Derek Allard2067d1a2008-11-13 22:59:24 +000048if ( ! function_exists('read_file'))
49{
50 function read_file($file)
51 {
52 if ( ! file_exists($file))
53 {
54 return FALSE;
55 }
Barry Mienydd671972010-10-04 16:33:58 +020056
Derek Allard2067d1a2008-11-13 22:59:24 +000057 if (function_exists('file_get_contents'))
58 {
Barry Mienydd671972010-10-04 16:33:58 +020059 return file_get_contents($file);
Derek Allard2067d1a2008-11-13 22:59:24 +000060 }
61
62 if ( ! $fp = @fopen($file, FOPEN_READ))
63 {
64 return FALSE;
65 }
Barry Mienydd671972010-10-04 16:33:58 +020066
Derek Allard2067d1a2008-11-13 22:59:24 +000067 flock($fp, LOCK_SH);
Barry Mienydd671972010-10-04 16:33:58 +020068
Derek Allard2067d1a2008-11-13 22:59:24 +000069 $data = '';
70 if (filesize($file) > 0)
71 {
72 $data =& fread($fp, filesize($file));
73 }
74
75 flock($fp, LOCK_UN);
76 fclose($fp);
77
78 return $data;
79 }
80}
Barry Mienydd671972010-10-04 16:33:58 +020081
Derek Allard2067d1a2008-11-13 22:59:24 +000082// ------------------------------------------------------------------------
83
84/**
85 * Write File
86 *
87 * Writes data to the file specified in the path.
88 * Creates a new file if non-existent.
89 *
Derek Allard2067d1a2008-11-13 22:59:24 +000090 * @param string path to file
91 * @param string file data
92 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +020093 */
Derek Allard2067d1a2008-11-13 22:59:24 +000094if ( ! function_exists('write_file'))
95{
96 function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE)
97 {
98 if ( ! $fp = @fopen($path, $mode))
99 {
100 return FALSE;
101 }
Barry Mienydd671972010-10-04 16:33:58 +0200102
Derek Allard2067d1a2008-11-13 22:59:24 +0000103 flock($fp, LOCK_EX);
104 fwrite($fp, $data);
105 flock($fp, LOCK_UN);
Barry Mienydd671972010-10-04 16:33:58 +0200106 fclose($fp);
Derek Allard2067d1a2008-11-13 22:59:24 +0000107
108 return TRUE;
109 }
110}
Barry Mienydd671972010-10-04 16:33:58 +0200111
Derek Allard2067d1a2008-11-13 22:59:24 +0000112// ------------------------------------------------------------------------
113
114/**
115 * Delete Files
116 *
117 * Deletes all files contained in the supplied directory path.
118 * Files must be writable or owned by the system in order to be deleted.
119 * If the second parameter is set to TRUE, any directories contained
120 * within the supplied base directory will be nuked as well.
121 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000122 * @param string path to file
123 * @param bool whether to delete any directories found in the path
Andrey Andreevfd6c2bc2012-04-03 16:21:48 +0300124 * @param int
125 * @param bool whether to skip deleting .htaccess and index page files
Derek Allard2067d1a2008-11-13 22:59:24 +0000126 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200127 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000128if ( ! function_exists('delete_files'))
129{
Andrey Andreevfd6c2bc2012-04-03 16:21:48 +0300130 function delete_files($path, $del_dir = FALSE, $level = 0, $htdocs = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200131 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 // Trim the trailing slash
Derek Jonesc37f0e12009-04-21 13:33:40 +0000133 $path = rtrim($path, DIRECTORY_SEPARATOR);
Barry Mienydd671972010-10-04 16:33:58 +0200134
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 if ( ! $current_dir = @opendir($path))
Greg Aker3e9519e2010-01-15 00:09:34 +0000136 {
Barry Mienydd671972010-10-04 16:33:58 +0200137 return FALSE;
Greg Aker3e9519e2010-01-15 00:09:34 +0000138 }
Barry Mienydd671972010-10-04 16:33:58 +0200139
Pascal Kriete45e3cdf2011-02-14 13:26:20 -0500140 while (FALSE !== ($filename = @readdir($current_dir)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000141 {
Andrey Andreevb2518642012-03-26 21:44:08 +0300142 if ($filename !== '.' && $filename !== '..')
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 {
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200144 if (is_dir($path.DIRECTORY_SEPARATOR.$filename) && $filename[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 {
Andrey Andreevfd6c2bc2012-04-03 16:21:48 +0300146 delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1, $htdocs);
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 }
Andrey Andreevfd6c2bc2012-04-03 16:21:48 +0300148 elseif ($htdocs === TRUE && ! preg_match('/^(\.htaccess|index\.(html|htm|php))$/', $filename))
Derek Allard2067d1a2008-11-13 22:59:24 +0000149 {
Andrey Andreevb2518642012-03-26 21:44:08 +0300150 @unlink($path.DIRECTORY_SEPARATOR.$filename);
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 }
152 }
153 }
154 @closedir($current_dir);
Barry Mienydd671972010-10-04 16:33:58 +0200155
Andrey Andreevb2518642012-03-26 21:44:08 +0300156 if ($del_dir == TRUE && $level > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000157 {
Greg Aker3e9519e2010-01-15 00:09:34 +0000158 return @rmdir($path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000159 }
Barry Mienydd671972010-10-04 16:33:58 +0200160
Greg Aker3e9519e2010-01-15 00:09:34 +0000161 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000162 }
163}
164
165// ------------------------------------------------------------------------
166
167/**
168 * Get Filenames
169 *
Barry Mienydd671972010-10-04 16:33:58 +0200170 * Reads the specified directory and builds an array containing the filenames.
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 * Any sub-folders contained within the specified path are read as well.
172 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 * @param string path to source
174 * @param bool whether to include the path as part of the filename
175 * @param bool internal variable to determine recursion status - do not use in calls
176 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200177 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000178if ( ! function_exists('get_filenames'))
179{
180 function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE)
181 {
182 static $_filedata = array();
Barry Mienydd671972010-10-04 16:33:58 +0200183
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 if ($fp = @opendir($source_dir))
185 {
186 // reset the array and make sure $source_dir has a trailing slash on the initial call
187 if ($_recursion === FALSE)
188 {
189 $_filedata = array();
190 $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
191 }
Barry Mienydd671972010-10-04 16:33:58 +0200192
Derek Allard2067d1a2008-11-13 22:59:24 +0000193 while (FALSE !== ($file = readdir($fp)))
194 {
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200195 if (@is_dir($source_dir.$file) && $file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000196 {
Barry Mienydd671972010-10-04 16:33:58 +0200197 get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000198 }
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200199 elseif ($file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000200 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000201 $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file;
202 }
203 }
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200204 closedir($fp);
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200205
Derek Allard2067d1a2008-11-13 22:59:24 +0000206 return $_filedata;
207 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200208
209 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000210 }
211}
212
213// --------------------------------------------------------------------
214
215/**
216 * Get Directory File Information
217 *
Barry Mienydd671972010-10-04 16:33:58 +0200218 * Reads the specified directory and builds an array containing the filenames,
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 * filesize, dates, and permissions
220 *
221 * Any sub-folders contained within the specified path are read as well.
222 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000223 * @param string path to source
Derek Jones626d39f2010-03-02 23:14:56 -0600224 * @param bool Look only at the top level directory specified?
Derek Allard2067d1a2008-11-13 22:59:24 +0000225 * @param bool internal variable to determine recursion status - do not use in calls
226 * @return array
Barry Mienydd671972010-10-04 16:33:58 +0200227 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000228if ( ! function_exists('get_dir_file_info'))
229{
Derek Jones788b00f2009-11-27 18:00:20 +0000230 function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000231 {
Derek Jones63dc27f2009-02-10 21:59:20 +0000232 static $_filedata = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000233 $relative_path = $source_dir;
Derek Jonesc37f0e12009-04-21 13:33:40 +0000234
Derek Allard2067d1a2008-11-13 22:59:24 +0000235 if ($fp = @opendir($source_dir))
236 {
237 // reset the array and make sure $source_dir has a trailing slash on the initial call
238 if ($_recursion === FALSE)
239 {
240 $_filedata = array();
241 $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
242 }
243
Derek Jones788b00f2009-11-27 18:00:20 +0000244 // foreach (scandir($source_dir, 1) as $file) // In addition to being PHP5+, scandir() is simply not as fast
Derek Allard2067d1a2008-11-13 22:59:24 +0000245 while (FALSE !== ($file = readdir($fp)))
246 {
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200247 if (@is_dir($source_dir.$file) && $file[0] !== '.' && $top_level_only === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000248 {
Barry Mienydd671972010-10-04 16:33:58 +0200249 get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE);
250 }
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200251 elseif ($file[0] !== '.')
Barry Mienydd671972010-10-04 16:33:58 +0200252 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 $_filedata[$file] = get_file_info($source_dir.$file);
254 $_filedata[$file]['relative_path'] = $relative_path;
255 }
256 }
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200257 closedir($fp);
Derek Jones788b00f2009-11-27 18:00:20 +0000258
Derek Allard2067d1a2008-11-13 22:59:24 +0000259 return $_filedata;
260 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200261
262 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000263 }
264}
265
266// --------------------------------------------------------------------
267
268/**
269* Get File Info
270*
271* Given a file and path, returns the name, path, size, date modified
272* Second parameter allows you to explicitly declare what information you want returned
273* Options are: name, server_path, size, date, readable, writable, executable, fileperms
274* Returns FALSE if the file cannot be found.
275*
Derek Jonesc37f0e12009-04-21 13:33:40 +0000276* @param string path to file
277* @param mixed array or comma separated string of information returned
Derek Allard2067d1a2008-11-13 22:59:24 +0000278* @return array
279*/
280if ( ! function_exists('get_file_info'))
281{
282 function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date'))
283 {
284
285 if ( ! file_exists($file))
286 {
287 return FALSE;
288 }
289
290 if (is_string($returned_values))
291 {
292 $returned_values = explode(',', $returned_values);
293 }
294
295 foreach ($returned_values as $key)
296 {
297 switch ($key)
298 {
299 case 'name':
Derek Jonesc37f0e12009-04-21 13:33:40 +0000300 $fileinfo['name'] = substr(strrchr($file, DIRECTORY_SEPARATOR), 1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000301 break;
302 case 'server_path':
303 $fileinfo['server_path'] = $file;
304 break;
305 case 'size':
306 $fileinfo['size'] = filesize($file);
307 break;
308 case 'date':
Robin Sowell73c19fc2010-04-09 11:18:26 -0400309 $fileinfo['date'] = filemtime($file);
Derek Allard2067d1a2008-11-13 22:59:24 +0000310 break;
311 case 'readable':
312 $fileinfo['readable'] = is_readable($file);
313 break;
314 case 'writable':
Derek Jones37f4b9c2011-07-01 17:56:50 -0500315 // There are known problems using is_weritable on IIS. It may not be reliable - consider fileperms()
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 $fileinfo['writable'] = is_writable($file);
317 break;
318 case 'executable':
319 $fileinfo['executable'] = is_executable($file);
320 break;
321 case 'fileperms':
322 $fileinfo['fileperms'] = fileperms($file);
323 break;
324 }
325 }
326
327 return $fileinfo;
328 }
329}
330
331// --------------------------------------------------------------------
332
333/**
334 * Get Mime by Extension
335 *
Barry Mienydd671972010-10-04 16:33:58 +0200336 * Translates a file extension into a mime type based on config/mimes.php.
Derek Allard2067d1a2008-11-13 22:59:24 +0000337 * Returns FALSE if it can't determine the type, or open the mime config file
338 *
339 * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience
340 * It should NOT be trusted, and should certainly NOT be used for security
341 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000342 * @param string path to file
343 * @return mixed
Barry Mienydd671972010-10-04 16:33:58 +0200344 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000345if ( ! function_exists('get_mime_by_extension'))
346{
347 function get_mime_by_extension($file)
348 {
Derek Allard95023112010-01-17 07:51:21 +0000349 $extension = strtolower(substr(strrchr($file, '.'), 1));
Derek Jonesc37f0e12009-04-21 13:33:40 +0000350
Derek Allard2067d1a2008-11-13 22:59:24 +0000351 global $mimes;
Derek Jonesc37f0e12009-04-21 13:33:40 +0000352
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 if ( ! is_array($mimes))
354 {
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200355 if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
Greg Akerd96f8822011-12-27 16:23:47 -0600356 {
357 include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
358 }
359 elseif (is_file(APPPATH.'config/mimes.php'))
360 {
361 include(APPPATH.'config/mimes.php');
362 }
Eric Barnes92808342011-03-18 09:02:37 -0400363
bubbafoley0ea04142011-03-17 14:55:41 -0500364 if ( ! is_array($mimes))
Derek Allard2067d1a2008-11-13 22:59:24 +0000365 {
366 return FALSE;
367 }
368 }
369
370 if (array_key_exists($extension, $mimes))
371 {
372 if (is_array($mimes[$extension]))
373 {
374 // Multiple mime types, just give the first one
375 return current($mimes[$extension]);
376 }
377 else
378 {
379 return $mimes[$extension];
380 }
381 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200382
383 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 }
385}
386
387// --------------------------------------------------------------------
388
389/**
390 * Symbolic Permissions
391 *
392 * Takes a numeric value representing a file's permissions and returns
393 * standard symbolic notation representing that value
394 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 * @param int
396 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200397 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000398if ( ! function_exists('symbolic_permissions'))
399{
400 function symbolic_permissions($perms)
Barry Mienydd671972010-10-04 16:33:58 +0200401 {
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200402 if (($perms & 0xC000) === 0xC000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000403 {
404 $symbolic = 's'; // Socket
405 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200406 elseif (($perms & 0xA000) === 0xA000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000407 {
408 $symbolic = 'l'; // Symbolic Link
409 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200410 elseif (($perms & 0x8000) === 0x8000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000411 {
412 $symbolic = '-'; // Regular
413 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200414 elseif (($perms & 0x6000) === 0x6000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 {
416 $symbolic = 'b'; // Block special
417 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200418 elseif (($perms & 0x4000) === 0x4000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 {
420 $symbolic = 'd'; // Directory
421 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200422 elseif (($perms & 0x2000) === 0x2000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000423 {
424 $symbolic = 'c'; // Character special
425 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200426 elseif (($perms & 0x1000) === 0x1000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 {
428 $symbolic = 'p'; // FIFO pipe
429 }
430 else
431 {
432 $symbolic = 'u'; // Unknown
433 }
434
435 // Owner
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200436 $symbolic .= (($perms & 0x0100) ? 'r' : '-')
437 . (($perms & 0x0080) ? 'w' : '-')
438 . (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000439
440 // Group
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200441 $symbolic .= (($perms & 0x0020) ? 'r' : '-')
442 . (($perms & 0x0010) ? 'w' : '-')
443 . (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000444
445 // World
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200446 $symbolic .= (($perms & 0x0004) ? 'r' : '-')
447 . (($perms & 0x0002) ? 'w' : '-')
448 . (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000449
Barry Mienydd671972010-10-04 16:33:58 +0200450 return $symbolic;
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 }
452}
453
454// --------------------------------------------------------------------
455
456/**
457 * Octal Permissions
458 *
459 * Takes a numeric value representing a file's permissions and returns
460 * a three character string representing the file's octal permissions
461 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000462 * @param int
463 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200464 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000465if ( ! function_exists('octal_permissions'))
466{
467 function octal_permissions($perms)
468 {
469 return substr(sprintf('%o', $perms), -3);
470 }
471}
472
Derek Allard2067d1a2008-11-13 22:59:24 +0000473/* End of file file_helper.php */
Andrey Andreevb2518642012-03-26 21:44:08 +0300474/* Location: ./system/helpers/file_helper.php */