path_helper.php

Go to the documentation of this file.
00001 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002 /**
00003  * CodeIgniter
00004  *
00005  * An open source application development framework for PHP 4.3.2 or newer
00006  *
00007  * @package             CodeIgniter
00008  * @author              ExpressionEngine Dev Team
00009  * @copyright   Copyright (c) 2006, EllisLab, Inc.
00010  * @license             http://codeigniter.com/user_guide/license.html
00011  * @link                http://codeigniter.com
00012  * @since               Version 1.0
00013  * @filesource
00014  */
00015 
00016 // ------------------------------------------------------------------------
00017 
00018 /**
00019  * CodeIgniter Path Helpers
00020  *
00021  * @package             CodeIgniter
00022  * @subpackage  Helpers
00023  * @category    Helpers
00024  * @author              ExpressionEngine Dev Team
00025  * @link                http://codeigniter.com/user_guide/helpers/xml_helper.html
00026  */
00027 
00028 // ------------------------------------------------------------------------
00029 
00030 /**
00031  * Set Realpath
00032  *
00033  * @access      public
00034  * @param       string
00035  * @param       bool    checks to see if the path exists
00036  * @return      string
00037  */     
00038 if ( ! function_exists('set_realpath'))
00039 {
00040         function set_realpath($path, $check_existance = TRUE)
00041         {
00042                 // Security check to make sure the path is NOT a URL.  No remote file inclusion!
00043                 if (preg_match("#^(http:\/\/|https:\/\/|www\.|ftp|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})#i", $path))
00044                 {
00045                         show_error('The path you submitted must be a local server path, not a URL');
00046                 }
00047         
00048                 // Resolve the path
00049                 if (function_exists('realpath') AND @realpath($path) !== FALSE)
00050                 {
00051                         $path = realpath($path).'/';
00052                 }
00053         
00054                 // Add a trailing slash
00055                 $path = preg_replace("#([^/])/*$#", "\\1/", $path);
00056         
00057                 // Make sure the path exists
00058                 if ($check_existance == TRUE)
00059                 {
00060                         if ( ! is_dir($path))
00061                         {
00062                                 show_error('Not a valid path: '.$path);
00063                         }
00064                 }
00065         
00066                 return $path;
00067         }
00068 }
00069 
00070 
00071 /* End of file path_helper.php */
00072 /* Location: ./system/helpers/path_helper.php */