set_realpath()

set_realpath($path[, $check_existance = FALSE])

Parameters:
  • $path (string) – Path
  • $check_existance (bool) – Whether to check if the path actually exists
Returns:

An absolute path

Return type:

string

This function will return a server path without symbolic links or relative directory structures. An optional second argument will cause an error to be triggered if the path cannot be resolved.

Examples:

$file = '/etc/php5/apache2/php.ini';
echo set_realpath($file); // Prints '/etc/php5/apache2/php.ini'

$non_existent_file = '/path/to/non-exist-file.txt';
echo set_realpath($non_existent_file, TRUE);    // Shows an error, as the path cannot be resolved
echo set_realpath($non_existent_file, FALSE);   // Prints '/path/to/non-exist-file.txt'

$directory = '/etc/php5';
echo set_realpath($directory);  // Prints '/etc/php5/'

$non_existent_directory = '/path/to/nowhere';
echo set_realpath($non_existent_directory, TRUE);       // Shows an error, as the path cannot be resolved
echo set_realpath($non_existent_directory, FALSE);      // Prints '/path/to/nowhere'
doc_CodeIgniter
2016-10-15 16:32:39
Comments
Leave a Comment

Please login to continue.