blob: ffcf468420cb1f5b098cd0a85754d0d9b0cd7772 [file] [log] [blame]
Derek Jones4b9c6292011-07-01 17:40:48 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Greg Aker0711dc82011-01-05 10:49:40 -06009 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @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
Barry Mienydd671972010-10-04 16:33:58 +020037 */
Derek Allard2067d1a2008-11-13 22:59:24 +000038if ( ! function_exists('set_realpath'))
39{
40 function set_realpath($path, $check_existance = FALSE)
41 {
Derek Jones4b9c6292011-07-01 17:40:48 -050042 // Security check to make sure the path is NOT a URL. No remote file inclusion!
Derek Allard2067d1a2008-11-13 22:59:24 +000043 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 }
Barry Mienydd671972010-10-04 16:33:58 +020047
Derek Allard2067d1a2008-11-13 22:59:24 +000048 // Resolve the path
49 if (function_exists('realpath') AND @realpath($path) !== FALSE)
50 {
51 $path = realpath($path).'/';
52 }
Barry Mienydd671972010-10-04 16:33:58 +020053
Derek Allard2067d1a2008-11-13 22:59:24 +000054 // Add a trailing slash
55 $path = preg_replace("#([^/])/*$#", "\\1/", $path);
Barry Mienydd671972010-10-04 16:33:58 +020056
Derek Allard2067d1a2008-11-13 22:59:24 +000057 // Make sure the path exists
58 if ($check_existance == TRUE)
59 {
60 if ( ! is_dir($path))
61 {
62 show_error('Not a valid path: '.$path);
63 }
64 }
Barry Mienydd671972010-10-04 16:33:58 +020065
Derek Allard2067d1a2008-11-13 22:59:24 +000066 return $path;
67 }
68}
69
70
71/* End of file path_helper.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +000072/* Location: ./system/helpers/path_helper.php */