converted to unix-style eol
[www-register-wizard.git] / helpers / file_helper.php
index 6378784..8078d96 100644 (file)
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
-/**\r
- * CodeIgniter\r
- *\r
- * An open source application development framework for PHP 4.3.2 or newer\r
- *\r
- * @package            CodeIgniter\r
- * @author             ExpressionEngine Dev Team\r
- * @copyright  Copyright (c) 2008, EllisLab, Inc.\r
- * @license            http://codeigniter.com/user_guide/license.html\r
- * @link               http://codeigniter.com\r
- * @since              Version 1.0\r
- * @filesource\r
- */\r
-\r
-// ------------------------------------------------------------------------\r
-\r
-/**\r
- * CodeIgniter File Helpers\r
- *\r
- * @package            CodeIgniter\r
- * @subpackage Helpers\r
- * @category   Helpers\r
- * @author             ExpressionEngine Dev Team\r
- * @link               http://codeigniter.com/user_guide/helpers/file_helper.html\r
- */\r
-\r
-// ------------------------------------------------------------------------\r
-\r
-/**\r
- * Read File\r
- *\r
- * Opens the file specfied in the path and returns it as a string.\r
- *\r
- * @access     public\r
- * @param      string  path to file\r
- * @return     string\r
- */    \r
-if ( ! function_exists('read_file'))\r
-{\r
-       function read_file($file)\r
-       {\r
-               if ( ! file_exists($file))\r
-               {\r
-                       return FALSE;\r
-               }\r
-       \r
-               if (function_exists('file_get_contents'))\r
-               {\r
-                       return file_get_contents($file);                \r
-               }\r
-\r
-               if ( ! $fp = @fopen($file, FOPEN_READ))\r
-               {\r
-                       return FALSE;\r
-               }\r
-               \r
-               flock($fp, LOCK_SH);\r
-       \r
-               $data = '';\r
-               if (filesize($file) > 0)\r
-               {\r
-                       $data =& fread($fp, filesize($file));\r
-               }\r
-\r
-               flock($fp, LOCK_UN);\r
-               fclose($fp);\r
-\r
-               return $data;\r
-       }\r
-}\r
-       \r
-// ------------------------------------------------------------------------\r
-\r
-/**\r
- * Write File\r
- *\r
- * Writes data to the file specified in the path.\r
- * Creates a new file if non-existent.\r
- *\r
- * @access     public\r
- * @param      string  path to file\r
- * @param      string  file data\r
- * @return     bool\r
- */    \r
-if ( ! function_exists('write_file'))\r
-{\r
-       function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE)\r
-       {\r
-               if ( ! $fp = @fopen($path, $mode))\r
-               {\r
-                       return FALSE;\r
-               }\r
-               \r
-               flock($fp, LOCK_EX);\r
-               fwrite($fp, $data);\r
-               flock($fp, LOCK_UN);\r
-               fclose($fp);    \r
-\r
-               return TRUE;\r
-       }\r
-}\r
-       \r
-// ------------------------------------------------------------------------\r
-\r
-/**\r
- * Delete Files\r
- *\r
- * Deletes all files contained in the supplied directory path.\r
- * Files must be writable or owned by the system in order to be deleted.\r
- * If the second parameter is set to TRUE, any directories contained\r
- * within the supplied base directory will be nuked as well.\r
- *\r
- * @access     public\r
- * @param      string  path to file\r
- * @param      bool    whether to delete any directories found in the path\r
- * @return     bool\r
- */    \r
-if ( ! function_exists('delete_files'))\r
-{\r
-       function delete_files($path, $del_dir = FALSE, $level = 0)\r
-       {       \r
-               // Trim the trailing slash\r
-               $path = preg_replace("|^(.+?)/*$|", "\\1", $path);\r
-               \r
-               if ( ! $current_dir = @opendir($path))\r
-                       return;\r
-       \r
-               while(FALSE !== ($filename = @readdir($current_dir)))\r
-               {\r
-                       if ($filename != "." and $filename != "..")\r
-                       {\r
-                               if (is_dir($path.'/'.$filename))\r
-                               {\r
-                                       // Ignore empty folders\r
-                                       if (substr($filename, 0, 1) != '.')\r
-                                       {\r
-                                               delete_files($path.'/'.$filename, $del_dir, $level + 1);\r
-                                       }\r
-                               }\r
-                               else\r
-                               {\r
-                                       unlink($path.'/'.$filename);\r
-                               }\r
-                       }\r
-               }\r
-               @closedir($current_dir);\r
-       \r
-               if ($del_dir == TRUE AND $level > 0)\r
-               {\r
-                       @rmdir($path);\r
-               }\r
-       }\r
-}\r
-\r
-// ------------------------------------------------------------------------\r
-\r
-/**\r
- * Get Filenames\r
- *\r
- * Reads the specified directory and builds an array containing the filenames.  \r
- * Any sub-folders contained within the specified path are read as well.\r
- *\r
- * @access     public\r
- * @param      string  path to source\r
- * @param      bool    whether to include the path as part of the filename\r
- * @param      bool    internal variable to determine recursion status - do not use in calls\r
- * @return     array\r
- */    \r
-if ( ! function_exists('get_filenames'))\r
-{\r
-       function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE)\r
-       {\r
-               static $_filedata = array();\r
-                               \r
-               if ($fp = @opendir($source_dir))\r
-               {\r
-                       // reset the array and make sure $source_dir has a trailing slash on the initial call\r
-                       if ($_recursion === FALSE)\r
-                       {\r
-                               $_filedata = array();\r
-                               $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;\r
-                       }\r
-                       \r
-                       while (FALSE !== ($file = readdir($fp)))\r
-                       {\r
-                               if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)\r
-                               {\r
-                                        get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);\r
-                               }\r
-                               elseif (strncmp($file, '.', 1) !== 0)\r
-                               {\r
-                       \r
-                                       $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file;\r
-                               }\r
-                       }\r
-                       return $_filedata;\r
-               }\r
-               else\r
-               {\r
-                       return FALSE;\r
-               }\r
-       }\r
-}\r
-\r
-// --------------------------------------------------------------------\r
-\r
-/**\r
- * Get Directory File Information\r
- *\r
- * Reads the specified directory and builds an array containing the filenames,  \r
- * filesize, dates, and permissions\r
- *\r
- * Any sub-folders contained within the specified path are read as well.\r
- *\r
- * @access     public\r
- * @param      string  path to source\r
- * @param      bool    whether to include the path as part of the filename\r
- * @param      bool    internal variable to determine recursion status - do not use in calls\r
- * @return     array\r
- */    \r
-if ( ! function_exists('get_dir_file_info'))\r
-{\r
-       function get_dir_file_info($source_dir, $include_path = FALSE, $_recursion = FALSE)\r
-       {\r
-               $_filedata = array();\r
-               $relative_path = $source_dir;\r
-                               \r
-               if ($fp = @opendir($source_dir))\r
-               {\r
-                       // reset the array and make sure $source_dir has a trailing slash on the initial call\r
-                       if ($_recursion === FALSE)\r
-                       {\r
-                               $_filedata = array();\r
-                               $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;\r
-                       }\r
-\r
-                       while (FALSE !== ($file = readdir($fp)))\r
-                       {\r
-                               if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)\r
-                               {\r
-                                        get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);\r
-                               }\r
-                               elseif (strncmp($file, '.', 1) !== 0)\r
-                               {\r
-                                       $_filedata[$file] = get_file_info($source_dir.$file);\r
-                                       $_filedata[$file]['relative_path'] = $relative_path;\r
-                               }\r
-                       }\r
-                       return $_filedata;\r
-               }\r
-               else\r
-               {\r
-                       return FALSE;\r
-               }\r
-       }\r
-}\r
-\r
-// --------------------------------------------------------------------\r
-\r
-/**\r
-* Get File Info\r
-*\r
-* Given a file and path, returns the name, path, size, date modified\r
-* Second parameter allows you to explicitly declare what information you want returned\r
-* Options are: name, server_path, size, date, readable, writable, executable, fileperms\r
-* Returns FALSE if the file cannot be found.\r
-*\r
-* @access      public\r
-* @param       string          path to file\r
-* @param       mixed           array or comma separated string of information returned\r
-* @return      array\r
-*/\r
-if ( ! function_exists('get_file_info'))\r
-{\r
-       function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date'))\r
-       {\r
-\r
-               if ( ! file_exists($file))\r
-               {\r
-                       return FALSE;\r
-               }\r
-\r
-               if (is_string($returned_values))\r
-               {\r
-                       $returned_values = explode(',', $returned_values);\r
-               }\r
-\r
-               foreach ($returned_values as $key)\r
-               {\r
-                       switch ($key)\r
-                       {\r
-                               case 'name':\r
-                                       $fileinfo['name'] = substr(strrchr($file, '/'), 1);\r
-                                       break;\r
-                               case 'server_path':\r
-                                       $fileinfo['server_path'] = $file;\r
-                                       break;\r
-                               case 'size':\r
-                                       $fileinfo['size'] = filesize($file);\r
-                                       break;\r
-                               case 'date':\r
-                                       $fileinfo['date'] = filectime($file);\r
-                                       break;\r
-                               case 'readable':\r
-                                       $fileinfo['readable'] = is_readable($file);\r
-                                       break;\r
-                               case 'writable':\r
-                                       // There are known problems using is_weritable on IIS.  It may not be reliable - consider fileperms()\r
-                                       $fileinfo['writable'] = is_writable($file);\r
-                                       break;\r
-                               case 'executable':\r
-                                       $fileinfo['executable'] = is_executable($file);\r
-                                       break;\r
-                               case 'fileperms':\r
-                                       $fileinfo['fileperms'] = fileperms($file);\r
-                                       break;\r
-                       }\r
-               }\r
-\r
-               return $fileinfo;\r
-       }\r
-}\r
-\r
-// --------------------------------------------------------------------\r
-\r
-/**\r
- * Get Mime by Extension\r
- *\r
- * Translates a file extension into a mime type based on config/mimes.php. \r
- * Returns FALSE if it can't determine the type, or open the mime config file\r
- *\r
- * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience\r
- * It should NOT be trusted, and should certainly NOT be used for security\r
- *\r
- * @access     public\r
- * @param      string  path to file\r
- * @return     mixed\r
- */    \r
-if ( ! function_exists('get_mime_by_extension'))\r
-{\r
-       function get_mime_by_extension($file)\r
-       {\r
-               $extension = substr(strrchr($file, '.'), 1);\r
-       \r
-               global $mimes;\r
-       \r
-               if ( ! is_array($mimes))\r
-               {\r
-                       if ( ! require_once(APPPATH.'config/mimes.php'))\r
-                       {\r
-                               return FALSE;\r
-                       }\r
-               }\r
-\r
-               if (array_key_exists($extension, $mimes))\r
-               {\r
-                       if (is_array($mimes[$extension]))\r
-                       {\r
-                               // Multiple mime types, just give the first one\r
-                               return current($mimes[$extension]);\r
-                       }\r
-                       else\r
-                       {\r
-                               return $mimes[$extension];\r
-                       }\r
-               }\r
-               else\r
-               {\r
-                       return FALSE;\r
-               }\r
-       }\r
-}\r
-\r
-// --------------------------------------------------------------------\r
-\r
-/**\r
- * Symbolic Permissions\r
- *\r
- * Takes a numeric value representing a file's permissions and returns\r
- * standard symbolic notation representing that value\r
- *\r
- * @access     public\r
- * @param      int\r
- * @return     string\r
- */    \r
-if ( ! function_exists('symbolic_permissions'))\r
-{\r
-       function symbolic_permissions($perms)\r
-       {       \r
-               if (($perms & 0xC000) == 0xC000)\r
-               {\r
-                       $symbolic = 's'; // Socket\r
-               }\r
-               elseif (($perms & 0xA000) == 0xA000)\r
-               {\r
-                       $symbolic = 'l'; // Symbolic Link\r
-               }\r
-               elseif (($perms & 0x8000) == 0x8000)\r
-               {\r
-                       $symbolic = '-'; // Regular\r
-               }\r
-               elseif (($perms & 0x6000) == 0x6000)\r
-               {\r
-                       $symbolic = 'b'; // Block special\r
-               }\r
-               elseif (($perms & 0x4000) == 0x4000)\r
-               {\r
-                       $symbolic = 'd'; // Directory\r
-               }\r
-               elseif (($perms & 0x2000) == 0x2000)\r
-               {\r
-                       $symbolic = 'c'; // Character special\r
-               }\r
-               elseif (($perms & 0x1000) == 0x1000)\r
-               {\r
-                       $symbolic = 'p'; // FIFO pipe\r
-               }\r
-               else\r
-               {\r
-                       $symbolic = 'u'; // Unknown\r
-               }\r
-\r
-               // Owner\r
-               $symbolic .= (($perms & 0x0100) ? 'r' : '-');\r
-               $symbolic .= (($perms & 0x0080) ? 'w' : '-');\r
-               $symbolic .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));\r
-\r
-               // Group\r
-               $symbolic .= (($perms & 0x0020) ? 'r' : '-');\r
-               $symbolic .= (($perms & 0x0010) ? 'w' : '-');\r
-               $symbolic .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));\r
-\r
-               // World\r
-               $symbolic .= (($perms & 0x0004) ? 'r' : '-');\r
-               $symbolic .= (($perms & 0x0002) ? 'w' : '-');\r
-               $symbolic .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));\r
-\r
-               return $symbolic;               \r
-       }\r
-}\r
-\r
-// --------------------------------------------------------------------\r
-\r
-/**\r
- * Octal Permissions\r
- *\r
- * Takes a numeric value representing a file's permissions and returns\r
- * a three character string representing the file's octal permissions\r
- *\r
- * @access     public\r
- * @param      int\r
- * @return     string\r
- */    \r
-if ( ! function_exists('octal_permissions'))\r
-{\r
-       function octal_permissions($perms)\r
-       {\r
-               return substr(sprintf('%o', $perms), -3);\r
-       }\r
-}\r
-\r
-\r
-/* End of file file_helper.php */\r
+<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package            CodeIgniter
+ * @author             ExpressionEngine Dev Team
+ * @copyright  Copyright (c) 2008, EllisLab, Inc.
+ * @license            http://codeigniter.com/user_guide/license.html
+ * @link               http://codeigniter.com
+ * @since              Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * CodeIgniter File Helpers
+ *
+ * @package            CodeIgniter
+ * @subpackage Helpers
+ * @category   Helpers
+ * @author             ExpressionEngine Dev Team
+ * @link               http://codeigniter.com/user_guide/helpers/file_helper.html
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Read File
+ *
+ * Opens the file specfied in the path and returns it as a string.
+ *
+ * @access     public
+ * @param      string  path to file
+ * @return     string
+ */    
+if ( ! function_exists('read_file'))
+{
+       function read_file($file)
+       {
+               if ( ! file_exists($file))
+               {
+                       return FALSE;
+               }
+       
+               if (function_exists('file_get_contents'))
+               {
+                       return file_get_contents($file);                
+               }
+
+               if ( ! $fp = @fopen($file, FOPEN_READ))
+               {
+                       return FALSE;
+               }
+               
+               flock($fp, LOCK_SH);
+       
+               $data = '';
+               if (filesize($file) > 0)
+               {
+                       $data =& fread($fp, filesize($file));
+               }
+
+               flock($fp, LOCK_UN);
+               fclose($fp);
+
+               return $data;
+       }
+}
+       
+// ------------------------------------------------------------------------
+
+/**
+ * Write File
+ *
+ * Writes data to the file specified in the path.
+ * Creates a new file if non-existent.
+ *
+ * @access     public
+ * @param      string  path to file
+ * @param      string  file data
+ * @return     bool
+ */    
+if ( ! function_exists('write_file'))
+{
+       function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE)
+       {
+               if ( ! $fp = @fopen($path, $mode))
+               {
+                       return FALSE;
+               }
+               
+               flock($fp, LOCK_EX);
+               fwrite($fp, $data);
+               flock($fp, LOCK_UN);
+               fclose($fp);    
+
+               return TRUE;
+       }
+}
+       
+// ------------------------------------------------------------------------
+
+/**
+ * Delete Files
+ *
+ * Deletes all files contained in the supplied directory path.
+ * Files must be writable or owned by the system in order to be deleted.
+ * If the second parameter is set to TRUE, any directories contained
+ * within the supplied base directory will be nuked as well.
+ *
+ * @access     public
+ * @param      string  path to file
+ * @param      bool    whether to delete any directories found in the path
+ * @return     bool
+ */    
+if ( ! function_exists('delete_files'))
+{
+       function delete_files($path, $del_dir = FALSE, $level = 0)
+       {       
+               // Trim the trailing slash
+               $path = preg_replace("|^(.+?)/*$|", "\\1", $path);
+               
+               if ( ! $current_dir = @opendir($path))
+                       return;
+       
+               while(FALSE !== ($filename = @readdir($current_dir)))
+               {
+                       if ($filename != "." and $filename != "..")
+                       {
+                               if (is_dir($path.'/'.$filename))
+                               {
+                                       // Ignore empty folders
+                                       if (substr($filename, 0, 1) != '.')
+                                       {
+                                               delete_files($path.'/'.$filename, $del_dir, $level + 1);
+                                       }
+                               }
+                               else
+                               {
+                                       unlink($path.'/'.$filename);
+                               }
+                       }
+               }
+               @closedir($current_dir);
+       
+               if ($del_dir == TRUE AND $level > 0)
+               {
+                       @rmdir($path);
+               }
+       }
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Get Filenames
+ *
+ * Reads the specified directory and builds an array containing the filenames.  
+ * Any sub-folders contained within the specified path are read as well.
+ *
+ * @access     public
+ * @param      string  path to source
+ * @param      bool    whether to include the path as part of the filename
+ * @param      bool    internal variable to determine recursion status - do not use in calls
+ * @return     array
+ */    
+if ( ! function_exists('get_filenames'))
+{
+       function get_filenames($source_dir, $include_path = FALSE, $_recursion = FALSE)
+       {
+               static $_filedata = array();
+                               
+               if ($fp = @opendir($source_dir))
+               {
+                       // reset the array and make sure $source_dir has a trailing slash on the initial call
+                       if ($_recursion === FALSE)
+                       {
+                               $_filedata = array();
+                               $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
+                       }
+                       
+                       while (FALSE !== ($file = readdir($fp)))
+                       {
+                               if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)
+                               {
+                                        get_filenames($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
+                               }
+                               elseif (strncmp($file, '.', 1) !== 0)
+                               {
+                       
+                                       $_filedata[] = ($include_path == TRUE) ? $source_dir.$file : $file;
+                               }
+                       }
+                       return $_filedata;
+               }
+               else
+               {
+                       return FALSE;
+               }
+       }
+}
+
+// --------------------------------------------------------------------
+
+/**
+ * Get Directory File Information
+ *
+ * Reads the specified directory and builds an array containing the filenames,  
+ * filesize, dates, and permissions
+ *
+ * Any sub-folders contained within the specified path are read as well.
+ *
+ * @access     public
+ * @param      string  path to source
+ * @param      bool    whether to include the path as part of the filename
+ * @param      bool    internal variable to determine recursion status - do not use in calls
+ * @return     array
+ */    
+if ( ! function_exists('get_dir_file_info'))
+{
+       function get_dir_file_info($source_dir, $include_path = FALSE, $_recursion = FALSE)
+       {
+               $_filedata = array();
+               $relative_path = $source_dir;
+                               
+               if ($fp = @opendir($source_dir))
+               {
+                       // reset the array and make sure $source_dir has a trailing slash on the initial call
+                       if ($_recursion === FALSE)
+                       {
+                               $_filedata = array();
+                               $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
+                       }
+
+                       while (FALSE !== ($file = readdir($fp)))
+                       {
+                               if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0)
+                               {
+                                        get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);
+                               }
+                               elseif (strncmp($file, '.', 1) !== 0)
+                               {
+                                       $_filedata[$file] = get_file_info($source_dir.$file);
+                                       $_filedata[$file]['relative_path'] = $relative_path;
+                               }
+                       }
+                       return $_filedata;
+               }
+               else
+               {
+                       return FALSE;
+               }
+       }
+}
+
+// --------------------------------------------------------------------
+
+/**
+* Get File Info
+*
+* Given a file and path, returns the name, path, size, date modified
+* Second parameter allows you to explicitly declare what information you want returned
+* Options are: name, server_path, size, date, readable, writable, executable, fileperms
+* Returns FALSE if the file cannot be found.
+*
+* @access      public
+* @param       string          path to file
+* @param       mixed           array or comma separated string of information returned
+* @return      array
+*/
+if ( ! function_exists('get_file_info'))
+{
+       function get_file_info($file, $returned_values = array('name', 'server_path', 'size', 'date'))
+       {
+
+               if ( ! file_exists($file))
+               {
+                       return FALSE;
+               }
+
+               if (is_string($returned_values))
+               {
+                       $returned_values = explode(',', $returned_values);
+               }
+
+               foreach ($returned_values as $key)
+               {
+                       switch ($key)
+                       {
+                               case 'name':
+                                       $fileinfo['name'] = substr(strrchr($file, '/'), 1);
+                                       break;
+                               case 'server_path':
+                                       $fileinfo['server_path'] = $file;
+                                       break;
+                               case 'size':
+                                       $fileinfo['size'] = filesize($file);
+                                       break;
+                               case 'date':
+                                       $fileinfo['date'] = filectime($file);
+                                       break;
+                               case 'readable':
+                                       $fileinfo['readable'] = is_readable($file);
+                                       break;
+                               case 'writable':
+                                       // There are known problems using is_weritable on IIS.  It may not be reliable - consider fileperms()
+                                       $fileinfo['writable'] = is_writable($file);
+                                       break;
+                               case 'executable':
+                                       $fileinfo['executable'] = is_executable($file);
+                                       break;
+                               case 'fileperms':
+                                       $fileinfo['fileperms'] = fileperms($file);
+                                       break;
+                       }
+               }
+
+               return $fileinfo;
+       }
+}
+
+// --------------------------------------------------------------------
+
+/**
+ * Get Mime by Extension
+ *
+ * Translates a file extension into a mime type based on config/mimes.php. 
+ * Returns FALSE if it can't determine the type, or open the mime config file
+ *
+ * Note: this is NOT an accurate way of determining file mime types, and is here strictly as a convenience
+ * It should NOT be trusted, and should certainly NOT be used for security
+ *
+ * @access     public
+ * @param      string  path to file
+ * @return     mixed
+ */    
+if ( ! function_exists('get_mime_by_extension'))
+{
+       function get_mime_by_extension($file)
+       {
+               $extension = substr(strrchr($file, '.'), 1);
+       
+               global $mimes;
+       
+               if ( ! is_array($mimes))
+               {
+                       if ( ! require_once(APPPATH.'config/mimes.php'))
+                       {
+                               return FALSE;
+                       }
+               }
+
+               if (array_key_exists($extension, $mimes))
+               {
+                       if (is_array($mimes[$extension]))
+                       {
+                               // Multiple mime types, just give the first one
+                               return current($mimes[$extension]);
+                       }
+                       else
+                       {
+                               return $mimes[$extension];
+                       }
+               }
+               else
+               {
+                       return FALSE;
+               }
+       }
+}
+
+// --------------------------------------------------------------------
+
+/**
+ * Symbolic Permissions
+ *
+ * Takes a numeric value representing a file's permissions and returns
+ * standard symbolic notation representing that value
+ *
+ * @access     public
+ * @param      int
+ * @return     string
+ */    
+if ( ! function_exists('symbolic_permissions'))
+{
+       function symbolic_permissions($perms)
+       {       
+               if (($perms & 0xC000) == 0xC000)
+               {
+                       $symbolic = 's'; // Socket
+               }
+               elseif (($perms & 0xA000) == 0xA000)
+               {
+                       $symbolic = 'l'; // Symbolic Link
+               }
+               elseif (($perms & 0x8000) == 0x8000)
+               {
+                       $symbolic = '-'; // Regular
+               }
+               elseif (($perms & 0x6000) == 0x6000)
+               {
+                       $symbolic = 'b'; // Block special
+               }
+               elseif (($perms & 0x4000) == 0x4000)
+               {
+                       $symbolic = 'd'; // Directory
+               }
+               elseif (($perms & 0x2000) == 0x2000)
+               {
+                       $symbolic = 'c'; // Character special
+               }
+               elseif (($perms & 0x1000) == 0x1000)
+               {
+                       $symbolic = 'p'; // FIFO pipe
+               }
+               else
+               {
+                       $symbolic = 'u'; // Unknown
+               }
+
+               // Owner
+               $symbolic .= (($perms & 0x0100) ? 'r' : '-');
+               $symbolic .= (($perms & 0x0080) ? 'w' : '-');
+               $symbolic .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
+
+               // Group
+               $symbolic .= (($perms & 0x0020) ? 'r' : '-');
+               $symbolic .= (($perms & 0x0010) ? 'w' : '-');
+               $symbolic .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
+
+               // World
+               $symbolic .= (($perms & 0x0004) ? 'r' : '-');
+               $symbolic .= (($perms & 0x0002) ? 'w' : '-');
+               $symbolic .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
+
+               return $symbolic;               
+       }
+}
+
+// --------------------------------------------------------------------
+
+/**
+ * Octal Permissions
+ *
+ * Takes a numeric value representing a file's permissions and returns
+ * a three character string representing the file's octal permissions
+ *
+ * @access     public
+ * @param      int
+ * @return     string
+ */    
+if ( ! function_exists('octal_permissions'))
+{
+       function octal_permissions($perms)
+       {
+               return substr(sprintf('%o', $perms), -3);
+       }
+}
+
+
+/* End of file file_helper.php */
 /* Location: ./system/helpers/file_helper.php */
\ No newline at end of file