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