The realpath
function in PHP is used to find the absolute path of the specified file. An absolute path is one that contains the path from the root to the element. The general syntax for the realpath
function is as follows:
realpath(string $path): string|false
The realpath
function has one mandatory parameter. This is the path
, which is the file we wish to check the path for.
The realpath
function returns the absolute path for a file. If it fails to retrieve the path, it returns FALSE.
The following example will help you understand the realpath
function. As shown below, the realpath
function prints the absolute path for the file main.txt
.
<?phpecho realpath("main.txt");?>
Free Resources