blob: 8cfe0f1c10fb5bb8a7438c803f9ad5e05b0c5d07 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
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
darwinel871754a2014-02-11 17:34:57 +010021 * @copyright Copyright (c) 2008 - 2014, 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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * CodeIgniter File Helpers
31 *
32 * @package CodeIgniter
33 * @subpackage Helpers
34 * @category Helpers
Derek Jonesf4a4bd82011-10-20 12:18:42 -050035 * @author EllisLab Dev Team
vkeranov50ec6a62012-07-12 11:00:06 +030036 * @link http://codeigniter.com/user_guide/helpers/file_helper.html
Derek Allard2067d1a2008-11-13 22:59:24 +000037 */
38
39// ------------------------------------------------------------------------
40
Derek Allard2067d1a2008-11-13 22:59:24 +000041if ( ! function_exists('read_file'))
42{
Timothy Warren01b129a2012-04-27 11:36:50 -040043 /**
44 * Read File
45 *
46 * Opens the file specfied in the path and returns it as a string.
47 *
Andrey Andreev29d909d2012-10-27 01:05:09 +030048 * @todo Remove in version 3.1+.
49 * @deprecated 3.0.0 It is now just an alias for PHP's native file_get_contents().
50 * @param string $file Path to file
51 * @return string File contents
Timothy Warren01b129a2012-04-27 11:36:50 -040052 */
Derek Allard2067d1a2008-11-13 22:59:24 +000053 function read_file($file)
54 {
Andrey Andreev596c51c2012-06-07 15:51:58 +030055 return @file_get_contents($file);
Derek Allard2067d1a2008-11-13 22:59:24 +000056 }
57}
Barry Mienydd671972010-10-04 16:33:58 +020058
Derek Allard2067d1a2008-11-13 22:59:24 +000059// ------------------------------------------------------------------------
60
Derek Allard2067d1a2008-11-13 22:59:24 +000061if ( ! function_exists('write_file'))
62{
Timothy Warren01b129a2012-04-27 11:36:50 -040063 /**
64 * Write File
65 *
66 * Writes data to the file specified in the path.
67 * Creates a new file if non-existent.
68 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +020069 * @param string $path File path
70 * @param string $data Data to write
71 * @param string $mode fopen() mode (default: 'wb')
Timothy Warren01b129a2012-04-27 11:36:50 -040072 * @return bool
73 */
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +020074 function write_file($path, $data, $mode = 'wb')
Derek Allard2067d1a2008-11-13 22:59:24 +000075 {
76 if ( ! $fp = @fopen($path, $mode))
77 {
78 return FALSE;
79 }
Barry Mienydd671972010-10-04 16:33:58 +020080
Derek Allard2067d1a2008-11-13 22:59:24 +000081 flock($fp, LOCK_EX);
Andrey Andreevd8b1ad32014-01-15 17:42:52 +020082
83 for ($written = 0, $length = strlen($data); $written < $length; $written += $result)
84 {
85 if (($result = fwrite($fp, substr($data, $written))) === FALSE)
86 {
87 break;
88 }
89 }
90
Derek Allard2067d1a2008-11-13 22:59:24 +000091 flock($fp, LOCK_UN);
Barry Mienydd671972010-10-04 16:33:58 +020092 fclose($fp);
Derek Allard2067d1a2008-11-13 22:59:24 +000093
Andrey Andreevd8b1ad32014-01-15 17:42:52 +020094 return is_int($result);
Derek Allard2067d1a2008-11-13 22:59:24 +000095 }
96}
Barry Mienydd671972010-10-04 16:33:58 +020097
Derek Allard2067d1a2008-11-13 22:59:24 +000098// ------------------------------------------------------------------------
99
Derek Allard2067d1a2008-11-13 22:59:24 +0000100if ( ! function_exists('delete_files'))
101{
Timothy Warren01b129a2012-04-27 11:36:50 -0400102 /**
103 * Delete Files
104 *
105 * Deletes all files contained in the supplied directory path.
106 * Files must be writable or owned by the system in order to be deleted.
107 * If the second parameter is set to TRUE, any directories contained
108 * within the supplied base directory will be nuked as well.
109 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200110 * @param string $path File path
111 * @param bool $del_dir Whether to delete any directories found in the path
112 * @param bool $htdocs Whether to skip deleting .htaccess and index page files
113 * @param int $_level Current directory depth level (default: 0; internal use only)
Timothy Warren01b129a2012-04-27 11:36:50 -0400114 * @return bool
115 */
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200116 function delete_files($path, $del_dir = FALSE, $htdocs = FALSE, $_level = 0)
Barry Mienydd671972010-10-04 16:33:58 +0200117 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 // Trim the trailing slash
Andrey Andreev256a18c2012-10-23 12:18:32 +0300119 $path = rtrim($path, '/\\');
Barry Mienydd671972010-10-04 16:33:58 +0200120
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 if ( ! $current_dir = @opendir($path))
Greg Aker3e9519e2010-01-15 00:09:34 +0000122 {
Barry Mienydd671972010-10-04 16:33:58 +0200123 return FALSE;
Greg Aker3e9519e2010-01-15 00:09:34 +0000124 }
Barry Mienydd671972010-10-04 16:33:58 +0200125
Pascal Kriete45e3cdf2011-02-14 13:26:20 -0500126 while (FALSE !== ($filename = @readdir($current_dir)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000127 {
Andrey Andreevb2518642012-03-26 21:44:08 +0300128 if ($filename !== '.' && $filename !== '..')
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 {
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200130 if (is_dir($path.DIRECTORY_SEPARATOR.$filename) && $filename[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000131 {
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200132 delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $htdocs, $_level + 1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 }
Andrey Andreev27228c92012-07-27 10:36:29 +0300134 elseif ($htdocs !== TRUE OR ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename))
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 {
Andrey Andreevb2518642012-03-26 21:44:08 +0300136 @unlink($path.DIRECTORY_SEPARATOR.$filename);
Derek Allard2067d1a2008-11-13 22:59:24 +0000137 }
138 }
139 }
Barry Mienydd671972010-10-04 16:33:58 +0200140
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200141 closedir($current_dir);
Barry Mienydd671972010-10-04 16:33:58 +0200142
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200143 return ($del_dir === TRUE && $_level > 0)
144 ? @rmdir($path)
145 : TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 }
147}
148
149// ------------------------------------------------------------------------
150
Derek Allard2067d1a2008-11-13 22:59:24 +0000151if ( ! function_exists('get_filenames'))
152{
Timothy Warren01b129a2012-04-27 11:36:50 -0400153 /**
154 * Get Filenames
155 *
156 * Reads the specified directory and builds an array containing the filenames.
157 * Any sub-folders contained within the specified path are read as well.
158 *
159 * @param string path to source
160 * @param bool whether to include the path as part of the filename
161 * @param bool internal variable to determine recursion status - do not use in calls
162 * @return array
163 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE)
165 {
166 static $_filedata = array();
Barry Mienydd671972010-10-04 16:33:58 +0200167
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 if ($fp = @opendir($source_dir))
169 {
170 // reset the array and make sure $source_dir has a trailing slash on the initial call
171 if ($_recursion === FALSE)
172 {
173 $_filedata = array();
174 $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
175 }
Barry Mienydd671972010-10-04 16:33:58 +0200176
Derek Allard2067d1a2008-11-13 22:59:24 +0000177 while (FALSE !== ($file = readdir($fp)))
178 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200179 if (is_dir($source_dir.$file) && $file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000180 {
Barry Mienydd671972010-10-04 16:33:58 +0200181 get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 }
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200183 elseif ($file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 {
Alex Bilbie773ccc32012-06-02 11:11:08 +0100185 $_filedata[] = ($include_path === TRUE) ? $source_dir.$file : $file;
Derek Allard2067d1a2008-11-13 22:59:24 +0000186 }
187 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200188
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200189 closedir($fp);
Derek Allard2067d1a2008-11-13 22:59:24 +0000190 return $_filedata;
191 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200192
193 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000194 }
195}
196
197// --------------------------------------------------------------------
198
Derek Allard2067d1a2008-11-13 22:59:24 +0000199if ( ! function_exists('get_dir_file_info'))
200{
Timothy Warren01b129a2012-04-27 11:36:50 -0400201 /**
202 * Get Directory File Information
203 *
204 * Reads the specified directory and builds an array containing the filenames,
205 * filesize, dates, and permissions
206 *
207 * Any sub-folders contained within the specified path are read as well.
208 *
209 * @param string path to source
210 * @param bool Look only at the top level directory specified?
211 * @param bool internal variable to determine recursion status - do not use in calls
212 * @return array
213 */
Derek Jones788b00f2009-11-27 18:00:20 +0000214 function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000215 {
Derek Jones63dc27f2009-02-10 21:59:20 +0000216 static $_filedata = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000217 $relative_path = $source_dir;
Derek Jonesc37f0e12009-04-21 13:33:40 +0000218
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 if ($fp = @opendir($source_dir))
220 {
221 // reset the array and make sure $source_dir has a trailing slash on the initial call
222 if ($_recursion === FALSE)
223 {
224 $_filedata = array();
225 $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
226 }
227
Derek Jones788b00f2009-11-27 18:00:20 +0000228 // 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 +0000229 while (FALSE !== ($file = readdir($fp)))
230 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200231 if (is_dir($source_dir.$file) && $file[0] !== '.' && $top_level_only === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 {
Barry Mienydd671972010-10-04 16:33:58 +0200233 get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE);
234 }
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200235 elseif ($file[0] !== '.')
Barry Mienydd671972010-10-04 16:33:58 +0200236 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 $_filedata[$file] = get_file_info($source_dir.$file);
238 $_filedata[$file]['relative_path'] = $relative_path;
239 }
240 }
Derek Jones788b00f2009-11-27 18:00:20 +0000241
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200242 closedir($fp);
Derek Allard2067d1a2008-11-13 22:59:24 +0000243 return $_filedata;
244 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200245
246 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000247 }
248}
249
250// --------------------------------------------------------------------
251
Derek Allard2067d1a2008-11-13 22:59:24 +0000252if ( ! function_exists('get_file_info'))
253{
Timothy Warren01b129a2012-04-27 11:36:50 -0400254 /**
255 * Get File Info
256 *
257 * Given a file and path, returns the name, path, size, date modified
258 * Second parameter allows you to explicitly declare what information you want returned
259 * Options are: name, server_path, size, date, readable, writable, executable, fileperms
260 * Returns FALSE if the file cannot be found.
261 *
262 * @param string path to file
263 * @param mixed array or comma separated string of information returned
264 * @return array
265 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000266 function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date'))
267 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000268 if ( ! file_exists($file))
269 {
270 return FALSE;
271 }
272
273 if (is_string($returned_values))
274 {
275 $returned_values = explode(',', $returned_values);
276 }
277
278 foreach ($returned_values as $key)
279 {
280 switch ($key)
281 {
282 case 'name':
Andrey Andreev12526cd2013-07-19 13:06:51 +0300283 $fileinfo['name'] = basename($file);
Derek Allard2067d1a2008-11-13 22:59:24 +0000284 break;
285 case 'server_path':
286 $fileinfo['server_path'] = $file;
287 break;
288 case 'size':
289 $fileinfo['size'] = filesize($file);
290 break;
291 case 'date':
Robin Sowell73c19fc2010-04-09 11:18:26 -0400292 $fileinfo['date'] = filemtime($file);
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 break;
294 case 'readable':
295 $fileinfo['readable'] = is_readable($file);
296 break;
297 case 'writable':
Andrey Andreev03077f92014-02-07 14:53:39 +0200298 $fileinfo['writable'] = is_really_writable($file);
Derek Allard2067d1a2008-11-13 22:59:24 +0000299 break;
300 case 'executable':
301 $fileinfo['executable'] = is_executable($file);
302 break;
303 case 'fileperms':
304 $fileinfo['fileperms'] = fileperms($file);
305 break;
306 }
307 }
308
309 return $fileinfo;
310 }
311}
312
313// --------------------------------------------------------------------
314
Derek Allard2067d1a2008-11-13 22:59:24 +0000315if ( ! function_exists('get_mime_by_extension'))
316{
Timothy Warren01b129a2012-04-27 11:36:50 -0400317 /**
318 * Get Mime by Extension
319 *
320 * Translates a file extension into a mime type based on config/mimes.php.
321 * Returns FALSE if it can't determine the type, or open the mime config file
322 *
323 * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience
324 * It should NOT be trusted, and should certainly NOT be used for security
325 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200326 * @param string $filename File name
327 * @return string
Timothy Warren01b129a2012-04-27 11:36:50 -0400328 */
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200329 function get_mime_by_extension($filename)
Derek Allard2067d1a2008-11-13 22:59:24 +0000330 {
Phil Sturgeon39b1c112012-06-04 16:51:14 -0500331 static $mimes;
Derek Jonesc37f0e12009-04-21 13:33:40 +0000332
Derek Allard2067d1a2008-11-13 22:59:24 +0000333 if ( ! is_array($mimes))
334 {
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300335 $mimes =& get_mimes();
Eric Barnes92808342011-03-18 09:02:37 -0400336
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300337 if (empty($mimes))
Derek Allard2067d1a2008-11-13 22:59:24 +0000338 {
339 return FALSE;
340 }
341 }
342
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200343 $extension = strtolower(substr(strrchr($filename, '.'), 1));
344
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300345 if (isset($mimes[$extension]))
Derek Allard2067d1a2008-11-13 22:59:24 +0000346 {
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300347 return is_array($mimes[$extension])
348 ? current($mimes[$extension]) // Multiple mime types, just give the first one
349 : $mimes[$extension];
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200351
352 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 }
354}
355
356// --------------------------------------------------------------------
357
Derek Allard2067d1a2008-11-13 22:59:24 +0000358if ( ! function_exists('symbolic_permissions'))
359{
Timothy Warren01b129a2012-04-27 11:36:50 -0400360 /**
361 * Symbolic Permissions
362 *
363 * Takes a numeric value representing a file's permissions and returns
364 * standard symbolic notation representing that value
365 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200366 * @param int $perms Permissions
Timothy Warren01b129a2012-04-27 11:36:50 -0400367 * @return string
368 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 function symbolic_permissions($perms)
Barry Mienydd671972010-10-04 16:33:58 +0200370 {
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200371 if (($perms & 0xC000) === 0xC000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000372 {
373 $symbolic = 's'; // Socket
374 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200375 elseif (($perms & 0xA000) === 0xA000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000376 {
377 $symbolic = 'l'; // Symbolic Link
378 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200379 elseif (($perms & 0x8000) === 0x8000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 {
381 $symbolic = '-'; // Regular
382 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200383 elseif (($perms & 0x6000) === 0x6000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 {
385 $symbolic = 'b'; // Block special
386 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200387 elseif (($perms & 0x4000) === 0x4000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000388 {
389 $symbolic = 'd'; // Directory
390 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200391 elseif (($perms & 0x2000) === 0x2000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 {
393 $symbolic = 'c'; // Character special
394 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200395 elseif (($perms & 0x1000) === 0x1000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 {
397 $symbolic = 'p'; // FIFO pipe
398 }
399 else
400 {
401 $symbolic = 'u'; // Unknown
402 }
403
404 // Owner
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200405 $symbolic .= (($perms & 0x0100) ? 'r' : '-')
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200406 .(($perms & 0x0080) ? 'w' : '-')
407 .(($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000408
409 // Group
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200410 $symbolic .= (($perms & 0x0020) ? 'r' : '-')
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200411 .(($perms & 0x0010) ? 'w' : '-')
412 .(($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000413
414 // World
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200415 $symbolic .= (($perms & 0x0004) ? 'r' : '-')
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200416 .(($perms & 0x0002) ? 'w' : '-')
417 .(($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000418
Barry Mienydd671972010-10-04 16:33:58 +0200419 return $symbolic;
Derek Allard2067d1a2008-11-13 22:59:24 +0000420 }
421}
422
423// --------------------------------------------------------------------
424
Derek Allard2067d1a2008-11-13 22:59:24 +0000425if ( ! function_exists('octal_permissions'))
426{
Timothy Warren01b129a2012-04-27 11:36:50 -0400427 /**
428 * Octal Permissions
429 *
430 * Takes a numeric value representing a file's permissions and returns
431 * a three character string representing the file's octal permissions
432 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200433 * @param int $perms Permissions
Timothy Warren01b129a2012-04-27 11:36:50 -0400434 * @return string
435 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 function octal_permissions($perms)
437 {
438 return substr(sprintf('%o', $perms), -3);
439 }
440}
441
Derek Allard2067d1a2008-11-13 22:59:24 +0000442/* End of file file_helper.php */
Andrey Andreevb2518642012-03-26 21:44:08 +0300443/* Location: ./system/helpers/file_helper.php */