Take two:
[www-register-wizard.git] / helpers / path_helper.php
1 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
2 /**\r
3  * CodeIgniter\r
4  *\r
5  * An open source application development framework for PHP 4.3.2 or newer\r
6  *\r
7  * @package             CodeIgniter\r
8  * @author              ExpressionEngine Dev Team\r
9  * @copyright   Copyright (c) 2008, EllisLab, Inc.\r
10  * @license             http://codeigniter.com/user_guide/license.html\r
11  * @link                http://codeigniter.com\r
12  * @since               Version 1.0\r
13  * @filesource\r
14  */\r
15 \r
16 // ------------------------------------------------------------------------\r
17 \r
18 /**\r
19  * CodeIgniter Path Helpers\r
20  *\r
21  * @package             CodeIgniter\r
22  * @subpackage  Helpers\r
23  * @category    Helpers\r
24  * @author              ExpressionEngine Dev Team\r
25  * @link                http://codeigniter.com/user_guide/helpers/xml_helper.html\r
26  */\r
27 \r
28 // ------------------------------------------------------------------------\r
29 \r
30 /**\r
31  * Set Realpath\r
32  *\r
33  * @access      public\r
34  * @param       string\r
35  * @param       bool    checks to see if the path exists\r
36  * @return      string\r
37  */     \r
38 if ( ! function_exists('set_realpath'))\r
39 {\r
40         function set_realpath($path, $check_existance = FALSE)\r
41         {\r
42                 // Security check to make sure the path is NOT a URL.  No remote file inclusion!\r
43                 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))\r
44                 {\r
45                         show_error('The path you submitted must be a local server path, not a URL');\r
46                 }\r
47         \r
48                 // Resolve the path\r
49                 if (function_exists('realpath') AND @realpath($path) !== FALSE)\r
50                 {\r
51                         $path = realpath($path).'/';\r
52                 }\r
53         \r
54                 // Add a trailing slash\r
55                 $path = preg_replace("#([^/])/*$#", "\\1/", $path);\r
56         \r
57                 // Make sure the path exists\r
58                 if ($check_existance == TRUE)\r
59                 {\r
60                         if ( ! is_dir($path))\r
61                         {\r
62                                 show_error('Not a valid path: '.$path);\r
63                         }\r
64                 }\r
65         \r
66                 return $path;\r
67         }\r
68 }\r
69 \r
70 \r
71 /* End of file path_helper.php */\r
72 /* Location: ./system/helpers/path_helper.php */