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 | |
| 8 | .. contents:: Page Contents |
| 9 | |
| 10 | Loading this Helper |
| 11 | =================== |
| 12 | |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 13 | This helper is loaded using the following code:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 14 | |
| 15 | $this->load->helper('path'); |
| 16 | |
| 17 | The following functions are available: |
| 18 | |
| 19 | set_realpath() |
| 20 | ============== |
| 21 | |
Derek Jones | b8c283a | 2013-07-19 16:02:53 -0700 | [diff] [blame^] | 22 | .. function:: set_realpath($path, $check_existance = FALSE) |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 23 | |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 24 | :param string $path: Path |
| 25 | :param bool $check_existance: Whether to check if the path actually exists |
| 26 | :returns: string |
| 27 | |
| 28 | This function will return a server path without symbolic links or |
| 29 | relative directory structures. An optional second argument will |
| 30 | cause an error to be triggered if the path cannot be resolved. |
| 31 | |
| 32 | Examples:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 33 | |
Andrey Andreev | ce707b4 | 2012-03-14 10:26:08 +0200 | [diff] [blame] | 34 | $file = '/etc/php5/apache2/php.ini'; |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 35 | echo set_realpath($file); // Prints '/etc/php5/apache2/php.ini' |
Taufan Aditya | f2915f2 | 2012-03-14 00:02:39 +0700 | [diff] [blame] | 36 | |
Andrey Andreev | ce707b4 | 2012-03-14 10:26:08 +0200 | [diff] [blame] | 37 | $non_existent_file = '/path/to/non-exist-file.txt'; |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 38 | echo set_realpath($non_existent_file, TRUE); // Shows an error, as the path cannot be resolved |
| 39 | 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] | 40 | |
Andrey Andreev | ce707b4 | 2012-03-14 10:26:08 +0200 | [diff] [blame] | 41 | $directory = '/etc/php5'; |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 42 | echo set_realpath($directory); // Prints '/etc/php5/' |
Derek Jones | b8c283a | 2013-07-19 16:02:53 -0700 | [diff] [blame^] | 43 | |
Andrey Andreev | ce707b4 | 2012-03-14 10:26:08 +0200 | [diff] [blame] | 44 | $non_existent_directory = '/path/to/nowhere'; |
Andrey Andreev | 53b8ef5 | 2012-11-08 21:38:53 +0200 | [diff] [blame] | 45 | echo set_realpath($non_existent_directory, TRUE); // Shows an error, as the path cannot be resolved |
| 46 | echo set_realpath($non_existent_directory, FALSE); // Prints '/path/to/nowhere' |