summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/helpers/path_helper.php19
-rw-r--r--user_guide_src/source/helpers/path_helper.rst20
2 files changed, 16 insertions, 23 deletions
diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php
index e4fc6f157..c31f0bdc5 100644
--- a/system/helpers/path_helper.php
+++ b/system/helpers/path_helper.php
@@ -25,8 +25,6 @@
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter Path Helpers
*
@@ -51,8 +49,8 @@ if ( ! function_exists('set_realpath'))
{
function set_realpath($path, $check_existance = FALSE)
{
- // Security check to make sure the path is NOT a URL. No remote file inclusion!
- 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))
+ // Security check to make sure the path is NOT a URL. No remote file inclusion!
+ 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))
{
show_error('The path you submitted must be a local server path, not a URL');
}
@@ -60,20 +58,15 @@ if ( ! function_exists('set_realpath'))
// Resolve the path
if (function_exists('realpath') && @realpath($path) !== FALSE)
{
- $realpath = realpath($path);
+ $path = realpath($path);
}
- else
- {
- $realpath = (is_dir($path) OR is_file($path)) ? $path : FALSE;
- }
-
- if ( ! $realpath)
+ elseif ($check_existance && ! is_dir($path) && ! is_file($path))
{
- return $check_existance ? show_error('Not a valid path: '.$path) : $path;
+ show_error('Not a valid path: '.$path);
}
// Add a trailing slash, if this is a directory
- return is_dir($realpath) ? rtrim($realpath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR : $realpath;
+ return is_dir($path) ? rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR : $path;
}
}
diff --git a/user_guide_src/source/helpers/path_helper.rst b/user_guide_src/source/helpers/path_helper.rst
index 43caffec2..847f5a08b 100644
--- a/user_guide_src/source/helpers/path_helper.rst
+++ b/user_guide_src/source/helpers/path_helper.rst
@@ -28,16 +28,16 @@ cannot be resolved.
::
- $file = '/etc/php5/apache2/php.ini';
- echo set_realpath($file); // returns "/etc/php5/apache2/php.ini"
+ $file = '/etc/php5/apache2/php.ini';
+ echo set_realpath($file); // returns "/etc/php5/apache2/php.ini"
- $non_existent_file = '/path/to/non-exist-file.txt';
- echo set_realpath($non_existent_file, TRUE); // returns an error, as the path could not be resolved
- echo set_realpath($non_existent_file, FALSE); // returns "/path/to/non-exist-file.txt"
+ $non_existent_file = '/path/to/non-exist-file.txt';
+ echo set_realpath($non_existent_file, TRUE); // shows an error, as the path cannot be resolved
+ echo set_realpath($non_existent_file, FALSE); // returns "/path/to/non-exist-file.txt"
- $directory = '/etc/php5';
- echo set_realpath($directory); // returns "/etc/php5/"
+ $directory = '/etc/php5';
+ echo set_realpath($directory); // returns "/etc/php5/"
- $non_existent_directory = '/path/to/nowhere';
- echo set_realpath($non_existent_directory, TRUE); // returns an error, as the path could not be resolved
- echo set_realpath($non_existent_directory, FALSE); // returns "/path/to/nowhere" \ No newline at end of file
+ $non_existent_directory = '/path/to/nowhere';
+ echo set_realpath($non_existent_directory, TRUE); // shows an error, as the path cannot be resolved
+ echo set_realpath($non_existent_directory, FALSE); // returns "/path/to/nowhere"