From 89338828264a6b50e0eb63c449a96f14f0f84076 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Mon, 12 Mar 2012 21:03:37 +0700 Subject: Path helper improvement --- system/helpers/path_helper.php | 16 +++++----------- user_guide_src/source/changelog.rst | 1 + user_guide_src/source/helpers/path_helper.rst | 11 +++++++---- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/system/helpers/path_helper.php b/system/helpers/path_helper.php index 2eb85fefa..1b9bdae75 100644 --- a/system/helpers/path_helper.php +++ b/system/helpers/path_helper.php @@ -58,21 +58,15 @@ if ( ! function_exists('set_realpath')) } // Resolve the path - if (function_exists('realpath') AND @realpath($path) !== FALSE) - { - $path = realpath($path); - } - - // Add a trailing slash - $path = rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; + $realpath = realpath($path); - // 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 f462e1b11..6900279ec 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() improvement. - Database diff --git a/user_guide_src/source/helpers/path_helper.rst b/user_guide_src/source/helpers/path_helper.rst index 1a70af458..6efd93cc1 100644 --- a/user_guide_src/source/helpers/path_helper.rst +++ b/user_guide_src/source/helpers/path_helper.rst @@ -28,10 +28,13 @@ cannot be resolved. :: + $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/passwd'; - echo set_realpath($directory); // returns "/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" - - + echo set_realpath($non_existent_directory, FALSE); // returns "/path/to/nowhere" \ No newline at end of file -- cgit v1.2.3-24-g4f1b