Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ########### |
| 2 | Path Helper |
| 3 | ########### |
| 4 | |
| 5 | The Path Helper file contains functions that permits you to work with |
| 6 | file paths on the server. |
| 7 | |
Derek Jones | 6851be1 | 2013-07-19 16:47:12 -0700 | [diff] [blame] | 8 | .. contents:: |
| 9 | :local: |
| 10 | |
| 11 | .. raw:: html |
| 12 | |
| 13 | <div class="custom-index container"></div> |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 14 | |
| 15 | Loading this Helper |
| 16 | =================== |
| 17 | |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 18 | This helper is loaded using the following code:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 19 | |
| 20 | $this->load->helper('path'); |
| 21 | |
Derek Jones | 6851be1 | 2013-07-19 16:47:12 -0700 | [diff] [blame] | 22 | Available Functions |
| 23 | =================== |
| 24 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 25 | The following functions are available: |
| 26 | |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 27 | |
Derek Jones | 6851be1 | 2013-07-19 16:47:12 -0700 | [diff] [blame] | 28 | .. function:: set_realpath($path[, $check_existance = FALSE]) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 29 | |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 30 | :param string $path: Path |
| 31 | :param bool $check_existance: Whether to check if the path actually exists |
Andrey Andreev | 3de130c | 2014-02-07 23:31:49 +0200 | [diff] [blame] | 32 | :returns: An absolute path |
| 33 | :rtype: string |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 34 | |
Derek Jones | 6851be1 | 2013-07-19 16:47:12 -0700 | [diff] [blame] | 35 | This function will return a server path without symbolic links or |
| 36 | relative directory structures. An optional second argument will |
| 37 | cause an error to be triggered if the path cannot be resolved. |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 38 | |
Derek Jones | 6851be1 | 2013-07-19 16:47:12 -0700 | [diff] [blame] | 39 | Examples:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 40 | |
Derek Jones | 6851be1 | 2013-07-19 16:47:12 -0700 | [diff] [blame] | 41 | $file = '/etc/php5/apache2/php.ini'; |
| 42 | echo set_realpath($file); // Prints '/etc/php5/apache2/php.ini' |
Taufan Aditya | f2915f2 | 2012-03-14 00:02:39 +0700 | [diff] [blame] | 43 | |
Derek Jones | 6851be1 | 2013-07-19 16:47:12 -0700 | [diff] [blame] | 44 | $non_existent_file = '/path/to/non-exist-file.txt'; |
| 45 | echo set_realpath($non_existent_file, TRUE); // Shows an error, as the path cannot be resolved |
| 46 | echo set_realpath($non_existent_file, FALSE); // Prints '/path/to/non-exist-file.txt' |
Taufan Aditya | f2915f2 | 2012-03-14 00:02:39 +0700 | [diff] [blame] | 47 | |
Derek Jones | 6851be1 | 2013-07-19 16:47:12 -0700 | [diff] [blame] | 48 | $directory = '/etc/php5'; |
| 49 | echo set_realpath($directory); // Prints '/etc/php5/' |
Derek Jones | b8c283a | 2013-07-19 16:02:53 -0700 | [diff] [blame] | 50 | |
Derek Jones | 6851be1 | 2013-07-19 16:47:12 -0700 | [diff] [blame] | 51 | $non_existent_directory = '/path/to/nowhere'; |
| 52 | echo set_realpath($non_existent_directory, TRUE); // Shows an error, as the path cannot be resolved |
| 53 | echo set_realpath($non_existent_directory, FALSE); // Prints '/path/to/nowhere' |