summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-03-14 09:12:36 +0100
committerAndrey Andreev <narf@bofh.bg>2012-03-14 09:12:36 +0100
commit3f103aaf1e182115a517117dfe44af2702667620 (patch)
treef207ef14a845bb4d8c31371c65839ea1ecf4263a
parent76062078b4f71740182eda6af9bd0d800111fedc (diff)
parentf2915f2787170d681a50db39a6650f48eefc8d7b (diff)
Merge pull request #1175 from toopay/path_helper
Path helper improvement
-rw-r--r--system/helpers/path_helper.php19
-rw-r--r--user_guide_src/source/changelog.rst1
-rw-r--r--user_guide_src/source/helpers/path_helper.rst16
3 files changed, 22 insertions, 14 deletions
diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php
index 2eb85fefa..e4fc6f157 100644
--- a/system/helpers/path_helper.php
+++ b/system/helpers/path_helper.php
@@ -58,21 +58,22 @@ if ( ! function_exists('set_realpath'))
}
// Resolve the path
- if (function_exists('realpath') AND @realpath($path) !== FALSE)
+ if (function_exists('realpath') && @realpath($path) !== FALSE)
{
- $path = realpath($path);
+ $realpath = realpath($path);
+ }
+ else
+ {
+ $realpath = (is_dir($path) OR is_file($path)) ? $path : FALSE;
}
- // Add a trailing slash
- $path = rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
-
- // Make sure the path exists
- if ($check_existance == TRUE && ! is_dir($path))
+ if ( ! $realpath)
{
- show_error('Not a valid path: '.$path);
+ return $check_existance ? show_error('Not a valid path: '.$path) : $path;
}
- return $path;
+ // Add a trailing slash, if this is a directory
+ return is_dir($realpath) ? rtrim($realpath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR : $realpath;
}
}
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index f9e742264..e679d4a40 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -45,6 +45,7 @@ Release Date: Not Released
- Added an optional third parameter to ``force_download()`` that enables/disables sending the actual file MIME type in the Content-Type header (disabled by default).
- Added a work-around in force_download() for a bug Android <= 2.1, where the filename extension needs to be in uppercase.
- form_dropdown() will now also take an array for unity with other form helpers.
+ - set_realpath() can now also handle file paths as opposed to just directories.
- Database
diff --git a/user_guide_src/source/helpers/path_helper.rst b/user_guide_src/source/helpers/path_helper.rst
index 1a70af458..43caffec2 100644
--- a/user_guide_src/source/helpers/path_helper.rst
+++ b/user_guide_src/source/helpers/path_helper.rst
@@ -28,10 +28,16 @@ cannot be resolved.
::
- $directory = '/etc/passwd';
- echo set_realpath($directory); // returns "/etc/passwd"
- $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"
+ $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"
+ $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