What is the realpath() function in PHP?
Overview
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
Parameters
The realpath function has one mandatory parameter. This is the path, which is the file we wish to check the path for.
Return value
The realpath function returns the absolute path for a file. If it fails to retrieve the path, it returns FALSE.
Example
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.
main.php
main.txt
<?phpecho realpath("main.txt");?>
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved