blob: 0587740b14038bd35d953c979a1e434400786f99 [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
Andrey Andreev80500af2013-01-01 08:16:53 +020021 * @copyright Copyright (c) 2008 - 2013, 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 }
140 @closedir($current_dir);
Barry Mienydd671972010-10-04 16:33:58 +0200141
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200142 if ($del_dir === TRUE && $_level > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 {
Greg Aker3e9519e2010-01-15 00:09:34 +0000144 return @rmdir($path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 }
Barry Mienydd671972010-10-04 16:33:58 +0200146
Greg Aker3e9519e2010-01-15 00:09:34 +0000147 return TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 }
149}
150
151// ------------------------------------------------------------------------
152
Derek Allard2067d1a2008-11-13 22:59:24 +0000153if ( ! function_exists('get_filenames'))
154{
Timothy Warren01b129a2012-04-27 11:36:50 -0400155 /**
156 * Get Filenames
157 *
158 * Reads the specified directory and builds an array containing the filenames.
159 * Any sub-folders contained within the specified path are read as well.
160 *
161 * @param string path to source
162 * @param bool whether to include the path as part of the filename
163 * @param bool internal variable to determine recursion status - do not use in calls
164 * @return array
165 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE)
167 {
168 static $_filedata = array();
Barry Mienydd671972010-10-04 16:33:58 +0200169
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 if ($fp = @opendir($source_dir))
171 {
172 // reset the array and make sure $source_dir has a trailing slash on the initial call
173 if ($_recursion === FALSE)
174 {
175 $_filedata = array();
176 $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
177 }
Barry Mienydd671972010-10-04 16:33:58 +0200178
Derek Allard2067d1a2008-11-13 22:59:24 +0000179 while (FALSE !== ($file = readdir($fp)))
180 {
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200181 if (@is_dir($source_dir.$file) && $file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 {
Barry Mienydd671972010-10-04 16:33:58 +0200183 get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 }
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200185 elseif ($file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000186 {
Alex Bilbie773ccc32012-06-02 11:11:08 +0100187 $_filedata[] = ($include_path === TRUE) ? $source_dir.$file : $file;
Derek Allard2067d1a2008-11-13 22:59:24 +0000188 }
189 }
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200190 closedir($fp);
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200191
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 return $_filedata;
193 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200194
195 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000196 }
197}
198
199// --------------------------------------------------------------------
200
Derek Allard2067d1a2008-11-13 22:59:24 +0000201if ( ! function_exists('get_dir_file_info'))
202{
Timothy Warren01b129a2012-04-27 11:36:50 -0400203 /**
204 * Get Directory File Information
205 *
206 * Reads the specified directory and builds an array containing the filenames,
207 * filesize, dates, and permissions
208 *
209 * Any sub-folders contained within the specified path are read as well.
210 *
211 * @param string path to source
212 * @param bool Look only at the top level directory specified?
213 * @param bool internal variable to determine recursion status - do not use in calls
214 * @return array
215 */
Derek Jones788b00f2009-11-27 18:00:20 +0000216 function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000217 {
Derek Jones63dc27f2009-02-10 21:59:20 +0000218 static $_filedata = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 $relative_path = $source_dir;
Derek Jonesc37f0e12009-04-21 13:33:40 +0000220
Derek Allard2067d1a2008-11-13 22:59:24 +0000221 if ($fp = @opendir($source_dir))
222 {
223 // reset the array and make sure $source_dir has a trailing slash on the initial call
224 if ($_recursion === FALSE)
225 {
226 $_filedata = array();
227 $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
228 }
229
Derek Jones788b00f2009-11-27 18:00:20 +0000230 // 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 +0000231 while (FALSE !== ($file = readdir($fp)))
232 {
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200233 if (@is_dir($source_dir.$file) && $file[0] !== '.' && $top_level_only === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 {
Barry Mienydd671972010-10-04 16:33:58 +0200235 get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE);
236 }
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200237 elseif ($file[0] !== '.')
Barry Mienydd671972010-10-04 16:33:58 +0200238 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 $_filedata[$file] = get_file_info($source_dir.$file);
240 $_filedata[$file]['relative_path'] = $relative_path;
241 }
242 }
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200243 closedir($fp);
Derek Jones788b00f2009-11-27 18:00:20 +0000244
Derek Allard2067d1a2008-11-13 22:59:24 +0000245 return $_filedata;
246 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200247
248 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000249 }
250}
251
252// --------------------------------------------------------------------
253
Derek Allard2067d1a2008-11-13 22:59:24 +0000254if ( ! function_exists('get_file_info'))
255{
Timothy Warren01b129a2012-04-27 11:36:50 -0400256 /**
257 * Get File Info
258 *
259 * Given a file and path, returns the name, path, size, date modified
260 * Second parameter allows you to explicitly declare what information you want returned
261 * Options are: name, server_path, size, date, readable, writable, executable, fileperms
262 * Returns FALSE if the file cannot be found.
263 *
264 * @param string path to file
265 * @param mixed array or comma separated string of information returned
266 * @return array
267 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000268 function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date'))
269 {
270
271 if ( ! file_exists($file))
272 {
273 return FALSE;
274 }
275
276 if (is_string($returned_values))
277 {
278 $returned_values = explode(',', $returned_values);
279 }
280
281 foreach ($returned_values as $key)
282 {
283 switch ($key)
284 {
285 case 'name':
Andrey Andreev12526cd2013-07-19 13:06:51 +0300286 $fileinfo['name'] = basename($file);
Derek Allard2067d1a2008-11-13 22:59:24 +0000287 break;
288 case 'server_path':
289 $fileinfo['server_path'] = $file;
290 break;
291 case 'size':
292 $fileinfo['size'] = filesize($file);
293 break;
294 case 'date':
Robin Sowell73c19fc2010-04-09 11:18:26 -0400295 $fileinfo['date'] = filemtime($file);
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 break;
297 case 'readable':
298 $fileinfo['readable'] = is_readable($file);
299 break;
300 case 'writable':
Derek Jones37f4b9c2011-07-01 17:56:50 -0500301 // There are known problems using is_weritable on IIS. It may not be reliable - consider fileperms()
Derek Allard2067d1a2008-11-13 22:59:24 +0000302 $fileinfo['writable'] = is_writable($file);
303 break;
304 case 'executable':
305 $fileinfo['executable'] = is_executable($file);
306 break;
307 case 'fileperms':
308 $fileinfo['fileperms'] = fileperms($file);
309 break;
310 }
311 }
312
313 return $fileinfo;
314 }
315}
316
317// --------------------------------------------------------------------
318
Derek Allard2067d1a2008-11-13 22:59:24 +0000319if ( ! function_exists('get_mime_by_extension'))
320{
Timothy Warren01b129a2012-04-27 11:36:50 -0400321 /**
322 * Get Mime by Extension
323 *
324 * Translates a file extension into a mime type based on config/mimes.php.
325 * Returns FALSE if it can't determine the type, or open the mime config file
326 *
327 * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience
328 * It should NOT be trusted, and should certainly NOT be used for security
329 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200330 * @param string $filename File name
331 * @return string
Timothy Warren01b129a2012-04-27 11:36:50 -0400332 */
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200333 function get_mime_by_extension($filename)
Derek Allard2067d1a2008-11-13 22:59:24 +0000334 {
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200335 $extension = strtolower(substr(strrchr($filename, '.'), 1));
Derek Jonesc37f0e12009-04-21 13:33:40 +0000336
Phil Sturgeon39b1c112012-06-04 16:51:14 -0500337 static $mimes;
Derek Jonesc37f0e12009-04-21 13:33:40 +0000338
Derek Allard2067d1a2008-11-13 22:59:24 +0000339 if ( ! is_array($mimes))
340 {
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300341 $mimes =& get_mimes();
Eric Barnes92808342011-03-18 09:02:37 -0400342
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300343 if (empty($mimes))
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 {
345 return FALSE;
346 }
347 }
348
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300349 if (isset($mimes[$extension]))
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 {
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300351 return is_array($mimes[$extension])
352 ? current($mimes[$extension]) // Multiple mime types, just give the first one
353 : $mimes[$extension];
Derek Allard2067d1a2008-11-13 22:59:24 +0000354 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200355
356 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000357 }
358}
359
360// --------------------------------------------------------------------
361
Derek Allard2067d1a2008-11-13 22:59:24 +0000362if ( ! function_exists('symbolic_permissions'))
363{
Timothy Warren01b129a2012-04-27 11:36:50 -0400364 /**
365 * Symbolic Permissions
366 *
367 * Takes a numeric value representing a file's permissions and returns
368 * standard symbolic notation representing that value
369 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200370 * @param int $perms Permissions
Timothy Warren01b129a2012-04-27 11:36:50 -0400371 * @return string
372 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 function symbolic_permissions($perms)
Barry Mienydd671972010-10-04 16:33:58 +0200374 {
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200375 if (($perms & 0xC000) === 0xC000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000376 {
377 $symbolic = 's'; // Socket
378 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200379 elseif (($perms & 0xA000) === 0xA000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 {
381 $symbolic = 'l'; // Symbolic Link
382 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200383 elseif (($perms & 0x8000) === 0x8000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 {
385 $symbolic = '-'; // Regular
386 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200387 elseif (($perms & 0x6000) === 0x6000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000388 {
389 $symbolic = 'b'; // Block special
390 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200391 elseif (($perms & 0x4000) === 0x4000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 {
393 $symbolic = 'd'; // Directory
394 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200395 elseif (($perms & 0x2000) === 0x2000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 {
397 $symbolic = 'c'; // Character special
398 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200399 elseif (($perms & 0x1000) === 0x1000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000400 {
401 $symbolic = 'p'; // FIFO pipe
402 }
403 else
404 {
405 $symbolic = 'u'; // Unknown
406 }
407
408 // Owner
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200409 $symbolic .= (($perms & 0x0100) ? 'r' : '-')
410 . (($perms & 0x0080) ? 'w' : '-')
411 . (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000412
413 // Group
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200414 $symbolic .= (($perms & 0x0020) ? 'r' : '-')
415 . (($perms & 0x0010) ? 'w' : '-')
416 . (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000417
418 // World
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200419 $symbolic .= (($perms & 0x0004) ? 'r' : '-')
420 . (($perms & 0x0002) ? 'w' : '-')
421 . (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000422
Barry Mienydd671972010-10-04 16:33:58 +0200423 return $symbolic;
Derek Allard2067d1a2008-11-13 22:59:24 +0000424 }
425}
426
427// --------------------------------------------------------------------
428
Derek Allard2067d1a2008-11-13 22:59:24 +0000429if ( ! function_exists('octal_permissions'))
430{
Timothy Warren01b129a2012-04-27 11:36:50 -0400431 /**
432 * Octal Permissions
433 *
434 * Takes a numeric value representing a file's permissions and returns
435 * a three character string representing the file's octal permissions
436 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200437 * @param int $perms Permissions
Timothy Warren01b129a2012-04-27 11:36:50 -0400438 * @return string
439 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 function octal_permissions($perms)
441 {
442 return substr(sprintf('%o', $perms), -3);
443 }
444}
445
Derek Allard2067d1a2008-11-13 22:59:24 +0000446/* End of file file_helper.php */
Andrey Andreevb2518642012-03-26 21:44:08 +0300447/* Location: ./system/helpers/file_helper.php */