blob: 1ff7287780888722650a64a0434567c370dce981 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Andrey Andreevfe9309d2015-01-09 17:48:58 +02005 * An open source application development framework for PHP
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +02007 * This content is released under the MIT License (MIT)
Andrey Andreev8bf6bb62012-01-06 16:11:04 +02008 *
Andrey Andreevfe9309d2015-01-09 17:48:58 +02009 * Copyright (c) 2014 - 2015, British Columbia Institute of Technology
Andrey Andreev8bf6bb62012-01-06 16:11:04 +020010 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020011 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
Derek Jonesf4a4bd82011-10-20 12:18:42 -050017 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020018 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * THE SOFTWARE.
28 *
29 * @package CodeIgniter
30 * @author EllisLab Dev Team
darwinel871754a2014-02-11 17:34:57 +010031 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
Andrey Andreevfe9309d2015-01-09 17:48:58 +020032 * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020033 * @license http://opensource.org/licenses/MIT MIT License
34 * @link http://codeigniter.com
35 * @since Version 1.0.0
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @filesource
37 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020038defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000039
Derek Allard2067d1a2008-11-13 22:59:24 +000040/**
41 * CodeIgniter File Helpers
42 *
43 * @package CodeIgniter
44 * @subpackage Helpers
45 * @category Helpers
Derek Jonesf4a4bd82011-10-20 12:18:42 -050046 * @author EllisLab Dev Team
vkeranov50ec6a62012-07-12 11:00:06 +030047 * @link http://codeigniter.com/user_guide/helpers/file_helper.html
Derek Allard2067d1a2008-11-13 22:59:24 +000048 */
49
50// ------------------------------------------------------------------------
51
Derek Allard2067d1a2008-11-13 22:59:24 +000052if ( ! function_exists('read_file'))
53{
Timothy Warren01b129a2012-04-27 11:36:50 -040054 /**
55 * Read File
56 *
57 * Opens the file specfied in the path and returns it as a string.
58 *
Andrey Andreev29d909d2012-10-27 01:05:09 +030059 * @todo Remove in version 3.1+.
60 * @deprecated 3.0.0 It is now just an alias for PHP's native file_get_contents().
61 * @param string $file Path to file
62 * @return string File contents
Timothy Warren01b129a2012-04-27 11:36:50 -040063 */
Derek Allard2067d1a2008-11-13 22:59:24 +000064 function read_file($file)
65 {
Andrey Andreev596c51c2012-06-07 15:51:58 +030066 return @file_get_contents($file);
Derek Allard2067d1a2008-11-13 22:59:24 +000067 }
68}
Barry Mienydd671972010-10-04 16:33:58 +020069
Derek Allard2067d1a2008-11-13 22:59:24 +000070// ------------------------------------------------------------------------
71
Derek Allard2067d1a2008-11-13 22:59:24 +000072if ( ! function_exists('write_file'))
73{
Timothy Warren01b129a2012-04-27 11:36:50 -040074 /**
75 * Write File
76 *
77 * Writes data to the file specified in the path.
78 * Creates a new file if non-existent.
79 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +020080 * @param string $path File path
81 * @param string $data Data to write
82 * @param string $mode fopen() mode (default: 'wb')
Timothy Warren01b129a2012-04-27 11:36:50 -040083 * @return bool
84 */
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +020085 function write_file($path, $data, $mode = 'wb')
Derek Allard2067d1a2008-11-13 22:59:24 +000086 {
87 if ( ! $fp = @fopen($path, $mode))
88 {
89 return FALSE;
90 }
Barry Mienydd671972010-10-04 16:33:58 +020091
Derek Allard2067d1a2008-11-13 22:59:24 +000092 flock($fp, LOCK_EX);
Andrey Andreevd8b1ad32014-01-15 17:42:52 +020093
Andrey Andreev1f5090a2014-06-03 15:40:30 +030094 for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result)
Andrey Andreevd8b1ad32014-01-15 17:42:52 +020095 {
96 if (($result = fwrite($fp, substr($data, $written))) === FALSE)
97 {
98 break;
99 }
100 }
101
Derek Allard2067d1a2008-11-13 22:59:24 +0000102 flock($fp, LOCK_UN);
Barry Mienydd671972010-10-04 16:33:58 +0200103 fclose($fp);
Derek Allard2067d1a2008-11-13 22:59:24 +0000104
Andrey Andreevd8b1ad32014-01-15 17:42:52 +0200105 return is_int($result);
Derek Allard2067d1a2008-11-13 22:59:24 +0000106 }
107}
Barry Mienydd671972010-10-04 16:33:58 +0200108
Derek Allard2067d1a2008-11-13 22:59:24 +0000109// ------------------------------------------------------------------------
110
Derek Allard2067d1a2008-11-13 22:59:24 +0000111if ( ! function_exists('delete_files'))
112{
Timothy Warren01b129a2012-04-27 11:36:50 -0400113 /**
114 * Delete Files
115 *
116 * Deletes all files contained in the supplied directory path.
117 * Files must be writable or owned by the system in order to be deleted.
118 * If the second parameter is set to TRUE, any directories contained
119 * within the supplied base directory will be nuked as well.
120 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200121 * @param string $path File path
122 * @param bool $del_dir Whether to delete any directories found in the path
123 * @param bool $htdocs Whether to skip deleting .htaccess and index page files
124 * @param int $_level Current directory depth level (default: 0; internal use only)
Timothy Warren01b129a2012-04-27 11:36:50 -0400125 * @return bool
126 */
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200127 function delete_files($path, $del_dir = FALSE, $htdocs = FALSE, $_level = 0)
Barry Mienydd671972010-10-04 16:33:58 +0200128 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 // Trim the trailing slash
Andrey Andreev256a18c2012-10-23 12:18:32 +0300130 $path = rtrim($path, '/\\');
Barry Mienydd671972010-10-04 16:33:58 +0200131
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 if ( ! $current_dir = @opendir($path))
Greg Aker3e9519e2010-01-15 00:09:34 +0000133 {
Barry Mienydd671972010-10-04 16:33:58 +0200134 return FALSE;
Greg Aker3e9519e2010-01-15 00:09:34 +0000135 }
Barry Mienydd671972010-10-04 16:33:58 +0200136
Pascal Kriete45e3cdf2011-02-14 13:26:20 -0500137 while (FALSE !== ($filename = @readdir($current_dir)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000138 {
Andrey Andreevb2518642012-03-26 21:44:08 +0300139 if ($filename !== '.' && $filename !== '..')
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 {
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200141 if (is_dir($path.DIRECTORY_SEPARATOR.$filename) && $filename[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000142 {
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200143 delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $htdocs, $_level + 1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000144 }
Andrey Andreev27228c92012-07-27 10:36:29 +0300145 elseif ($htdocs !== TRUE OR ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename))
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 {
Andrey Andreevb2518642012-03-26 21:44:08 +0300147 @unlink($path.DIRECTORY_SEPARATOR.$filename);
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 }
149 }
150 }
Barry Mienydd671972010-10-04 16:33:58 +0200151
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200152 closedir($current_dir);
Barry Mienydd671972010-10-04 16:33:58 +0200153
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200154 return ($del_dir === TRUE && $_level > 0)
155 ? @rmdir($path)
156 : TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000157 }
158}
159
160// ------------------------------------------------------------------------
161
Derek Allard2067d1a2008-11-13 22:59:24 +0000162if ( ! function_exists('get_filenames'))
163{
Timothy Warren01b129a2012-04-27 11:36:50 -0400164 /**
165 * Get Filenames
166 *
167 * Reads the specified directory and builds an array containing the filenames.
168 * Any sub-folders contained within the specified path are read as well.
169 *
170 * @param string path to source
171 * @param bool whether to include the path as part of the filename
172 * @param bool internal variable to determine recursion status - do not use in calls
173 * @return array
174 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE)
176 {
177 static $_filedata = array();
Barry Mienydd671972010-10-04 16:33:58 +0200178
Derek Allard2067d1a2008-11-13 22:59:24 +0000179 if ($fp = @opendir($source_dir))
180 {
181 // reset the array and make sure $source_dir has a trailing slash on the initial call
182 if ($_recursion === FALSE)
183 {
184 $_filedata = array();
185 $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
186 }
Barry Mienydd671972010-10-04 16:33:58 +0200187
Derek Allard2067d1a2008-11-13 22:59:24 +0000188 while (FALSE !== ($file = readdir($fp)))
189 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200190 if (is_dir($source_dir.$file) && $file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 {
Barry Mienydd671972010-10-04 16:33:58 +0200192 get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000193 }
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200194 elseif ($file[0] !== '.')
Derek Allard2067d1a2008-11-13 22:59:24 +0000195 {
Alex Bilbie773ccc32012-06-02 11:11:08 +0100196 $_filedata[] = ($include_path === TRUE) ? $source_dir.$file : $file;
Derek Allard2067d1a2008-11-13 22:59:24 +0000197 }
198 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200199
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200200 closedir($fp);
Derek Allard2067d1a2008-11-13 22:59:24 +0000201 return $_filedata;
202 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200203
204 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000205 }
206}
207
208// --------------------------------------------------------------------
209
Derek Allard2067d1a2008-11-13 22:59:24 +0000210if ( ! function_exists('get_dir_file_info'))
211{
Timothy Warren01b129a2012-04-27 11:36:50 -0400212 /**
213 * Get Directory File Information
214 *
215 * Reads the specified directory and builds an array containing the filenames,
216 * filesize, dates, and permissions
217 *
218 * Any sub-folders contained within the specified path are read as well.
219 *
220 * @param string path to source
221 * @param bool Look only at the top level directory specified?
222 * @param bool internal variable to determine recursion status - do not use in calls
223 * @return array
224 */
Derek Jones788b00f2009-11-27 18:00:20 +0000225 function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 {
Derek Jones63dc27f2009-02-10 21:59:20 +0000227 static $_filedata = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000228 $relative_path = $source_dir;
Derek Jonesc37f0e12009-04-21 13:33:40 +0000229
Derek Allard2067d1a2008-11-13 22:59:24 +0000230 if ($fp = @opendir($source_dir))
231 {
232 // reset the array and make sure $source_dir has a trailing slash on the initial call
233 if ($_recursion === FALSE)
234 {
235 $_filedata = array();
236 $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
237 }
238
Andrey Andreevf9a615a2014-09-28 20:24:06 +0300239 // Used to be foreach (scandir($source_dir, 1) as $file), but scandir() is simply not as fast
Derek Allard2067d1a2008-11-13 22:59:24 +0000240 while (FALSE !== ($file = readdir($fp)))
241 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200242 if (is_dir($source_dir.$file) && $file[0] !== '.' && $top_level_only === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000243 {
Barry Mienydd671972010-10-04 16:33:58 +0200244 get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE);
245 }
Andrey Andreev3b8ad8f2012-01-10 18:09:07 +0200246 elseif ($file[0] !== '.')
Barry Mienydd671972010-10-04 16:33:58 +0200247 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000248 $_filedata[$file] = get_file_info($source_dir.$file);
249 $_filedata[$file]['relative_path'] = $relative_path;
250 }
251 }
Derek Jones788b00f2009-11-27 18:00:20 +0000252
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200253 closedir($fp);
Derek Allard2067d1a2008-11-13 22:59:24 +0000254 return $_filedata;
255 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200256
257 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000258 }
259}
260
261// --------------------------------------------------------------------
262
Derek Allard2067d1a2008-11-13 22:59:24 +0000263if ( ! function_exists('get_file_info'))
264{
Timothy Warren01b129a2012-04-27 11:36:50 -0400265 /**
266 * Get File Info
267 *
268 * Given a file and path, returns the name, path, size, date modified
269 * Second parameter allows you to explicitly declare what information you want returned
270 * Options are: name, server_path, size, date, readable, writable, executable, fileperms
271 * Returns FALSE if the file cannot be found.
272 *
273 * @param string path to file
274 * @param mixed array or comma separated string of information returned
275 * @return array
276 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000277 function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date'))
278 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000279 if ( ! file_exists($file))
280 {
281 return FALSE;
282 }
283
284 if (is_string($returned_values))
285 {
286 $returned_values = explode(',', $returned_values);
287 }
288
289 foreach ($returned_values as $key)
290 {
291 switch ($key)
292 {
293 case 'name':
Andrey Andreev12526cd2013-07-19 13:06:51 +0300294 $fileinfo['name'] = basename($file);
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 break;
296 case 'server_path':
297 $fileinfo['server_path'] = $file;
298 break;
299 case 'size':
300 $fileinfo['size'] = filesize($file);
301 break;
302 case 'date':
Robin Sowell73c19fc2010-04-09 11:18:26 -0400303 $fileinfo['date'] = filemtime($file);
Derek Allard2067d1a2008-11-13 22:59:24 +0000304 break;
305 case 'readable':
306 $fileinfo['readable'] = is_readable($file);
307 break;
308 case 'writable':
Andrey Andreev03077f92014-02-07 14:53:39 +0200309 $fileinfo['writable'] = is_really_writable($file);
Derek Allard2067d1a2008-11-13 22:59:24 +0000310 break;
311 case 'executable':
312 $fileinfo['executable'] = is_executable($file);
313 break;
314 case 'fileperms':
315 $fileinfo['fileperms'] = fileperms($file);
316 break;
317 }
318 }
319
320 return $fileinfo;
321 }
322}
323
324// --------------------------------------------------------------------
325
Derek Allard2067d1a2008-11-13 22:59:24 +0000326if ( ! function_exists('get_mime_by_extension'))
327{
Timothy Warren01b129a2012-04-27 11:36:50 -0400328 /**
329 * Get Mime by Extension
330 *
331 * Translates a file extension into a mime type based on config/mimes.php.
332 * Returns FALSE if it can't determine the type, or open the mime config file
333 *
334 * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience
335 * It should NOT be trusted, and should certainly NOT be used for security
336 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200337 * @param string $filename File name
338 * @return string
Timothy Warren01b129a2012-04-27 11:36:50 -0400339 */
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200340 function get_mime_by_extension($filename)
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 {
Phil Sturgeon39b1c112012-06-04 16:51:14 -0500342 static $mimes;
Derek Jonesc37f0e12009-04-21 13:33:40 +0000343
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 if ( ! is_array($mimes))
345 {
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300346 $mimes =& get_mimes();
Eric Barnes92808342011-03-18 09:02:37 -0400347
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300348 if (empty($mimes))
Derek Allard2067d1a2008-11-13 22:59:24 +0000349 {
350 return FALSE;
351 }
352 }
353
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200354 $extension = strtolower(substr(strrchr($filename, '.'), 1));
355
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300356 if (isset($mimes[$extension]))
Derek Allard2067d1a2008-11-13 22:59:24 +0000357 {
Andrey Andreev6ef498b2012-06-05 22:01:58 +0300358 return is_array($mimes[$extension])
359 ? current($mimes[$extension]) // Multiple mime types, just give the first one
360 : $mimes[$extension];
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200362
363 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000364 }
365}
366
367// --------------------------------------------------------------------
368
Derek Allard2067d1a2008-11-13 22:59:24 +0000369if ( ! function_exists('symbolic_permissions'))
370{
Timothy Warren01b129a2012-04-27 11:36:50 -0400371 /**
372 * Symbolic Permissions
373 *
374 * Takes a numeric value representing a file's permissions and returns
375 * standard symbolic notation representing that value
376 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200377 * @param int $perms Permissions
Timothy Warren01b129a2012-04-27 11:36:50 -0400378 * @return string
379 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 function symbolic_permissions($perms)
Barry Mienydd671972010-10-04 16:33:58 +0200381 {
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200382 if (($perms & 0xC000) === 0xC000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 {
384 $symbolic = 's'; // Socket
385 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200386 elseif (($perms & 0xA000) === 0xA000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000387 {
388 $symbolic = 'l'; // Symbolic Link
389 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200390 elseif (($perms & 0x8000) === 0x8000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000391 {
392 $symbolic = '-'; // Regular
393 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200394 elseif (($perms & 0x6000) === 0x6000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 {
396 $symbolic = 'b'; // Block special
397 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200398 elseif (($perms & 0x4000) === 0x4000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000399 {
400 $symbolic = 'd'; // Directory
401 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200402 elseif (($perms & 0x2000) === 0x2000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000403 {
404 $symbolic = 'c'; // Character special
405 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200406 elseif (($perms & 0x1000) === 0x1000)
Derek Allard2067d1a2008-11-13 22:59:24 +0000407 {
408 $symbolic = 'p'; // FIFO pipe
409 }
410 else
411 {
412 $symbolic = 'u'; // Unknown
413 }
414
415 // Owner
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200416 $symbolic .= (($perms & 0x0100) ? 'r' : '-')
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200417 .(($perms & 0x0080) ? 'w' : '-')
418 .(($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000419
420 // Group
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200421 $symbolic .= (($perms & 0x0020) ? 'r' : '-')
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200422 .(($perms & 0x0010) ? 'w' : '-')
423 .(($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000424
425 // World
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200426 $symbolic .= (($perms & 0x0004) ? 'r' : '-')
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200427 .(($perms & 0x0002) ? 'w' : '-')
428 .(($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000429
Barry Mienydd671972010-10-04 16:33:58 +0200430 return $symbolic;
Derek Allard2067d1a2008-11-13 22:59:24 +0000431 }
432}
433
434// --------------------------------------------------------------------
435
Derek Allard2067d1a2008-11-13 22:59:24 +0000436if ( ! function_exists('octal_permissions'))
437{
Timothy Warren01b129a2012-04-27 11:36:50 -0400438 /**
439 * Octal Permissions
440 *
441 * Takes a numeric value representing a file's permissions and returns
442 * a three character string representing the file's octal permissions
443 *
Andrey Andreevf6d9a7c2012-11-08 17:27:57 +0200444 * @param int $perms Permissions
Timothy Warren01b129a2012-04-27 11:36:50 -0400445 * @return string
446 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 function octal_permissions($perms)
448 {
449 return substr(sprintf('%o', $perms), -3);
450 }
451}
452
Derek Allard2067d1a2008-11-13 22:59:24 +0000453/* End of file file_helper.php */
Andrey Andreevb2518642012-03-26 21:44:08 +0300454/* Location: ./system/helpers/file_helper.php */