The realpath() function in PHP is an inbuilt function which is used to return the canonicalized absolute pathname.
The realpath() function removes all symbolic links such as ‘/./’ ‘/../’ and extra ‘/’ and returns the absolute pathname.
The path is sent as a parameter to the realpath() function and it returns the absolute pathname on success and a False on failure.
The realpath() function in PHP accepts only one parameter.
- path : It is a mandatory parameter which specifies the symbolic path whose absolute path the user wants to know.
It returns the absolute pathname on success and a False on failure.
Errors And Exception
- The realpath() function returns False if the running script does not have executable permissions on all directories in the hierarchy.
- The function realpath() will not work for a file which is inside a Phar as such a path is not a real path.
- Some filesystem functions may return unexpected results for files which are larger than 2GB since PHP’s integer type is signed and many platforms use 32bit integers.
Input : echo realpath("gfg.txt"); Output : C:\xampp\htdocs\filehandling\gfg.txt Input : chdir('/docs/assignment/'); echo realpath('./../../gfg/articles'); Output : /gfg/articles
Below programs illustrate the realpath() function.
Suppose there is a file named “gfg.txt”
- Node.js | fs.realpath() Method
- Node.js | fsPromises.realpath() Method
- How to get the function name inside a function in PHP ?
- PHP Ds\Set sum() Function
- CSS | url() Function
- PHP | Ds\Map get() Function
- D3.js | d3.rgb() Function
- PHP | pos() Function
- p5.js | max() function
- p5.js | second() function
- p5.js | hue() function
- p5.js | cos() function
- p5.js | red() function
- p5.js | min() function
- PHP | ord() Function
- CSS | var() Function
- D3.js zip() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.