Codeigniter Path Helper -This helper contains function that returns a server path without symbolic links or related directory structures. An optional second argument will cause an error to be triggered if the path cannot be resolved. $this->load->helper(‘path’); is used to load the helper. The path helper file contains functions that authorize you to work with file paths on the server. Here in this tutorial we are going to explain how to use path helper in codeigniter.
Codeigniter path helper example
Let us first see how to load path helper in codeigniter and then use its function-
Load path helper
How to load path helper in codeingniter example:
$this->load->helper('path'); |
Functions:-
The following functions are available in path helper.
-
Absolute path OR real path
- $path (string) : Path
- $check_existance (bool) : Whether to check if the path actually exists
- Returns : An absolute path
- Return type : String
Syntax of absolute path function is
Syntax of absolute path function is:-
set_realpath($path[$check_existance = FALSE]) |
Parameters:
EXAMPLE
Here is simple example of absolute path OR real path.
Absolute path OR real path in codeigniter example:-
//Controllers part public function checkPath() { $this->load->helper('path'); $this->load->view('checkPath_view'); } // Views parts <?php $directory = 'localhost/codeigniter/etc/php5';??> <?php echo set_realpath($directory);??> <br/> <?php $non_existent_directory = '/path/to/nowhere';??> <?php echo set_realpath($non_existent_directory, TRUE);??> <br/> <?php echo set_realpath($non_existent_directory, FALSE); ??> |
The output of the above example will be something like this –