Given full path, find file name in the path.
Input : path = /testweb/var/www/mywebsite/htdocs/home.php
Output : home.php
Input : path = /testweb/var/www/mywebsite/htdocs/abc.txt
Output : abc.txt
1. Using basename():
$filename = basename(path, suffix);
Path is a required field. It specifies the path to check.
Suffix is a optional field. It specifies a file extension. If the filename has this file extension, the file extension will not show.
2. Using pathinfo():
Also we can use the function pathinfo() which creates an array with the parts of the path we want to use.
$filename = pathinfo(path);
when we want to access the file name we will use $filename[‘basename’].
- How to get file input by selected file name without path using jQuery ?
- How to check the given path is file or directory in node.js ?
- How to reset selected file with input tag file type in Angular 9?
- D3.js | Path
- SVG Path Element
- Routing Path for ExpressJS
- D3.js | Path.rect() Function
- D3.js | Path.moveTo() Function
- Express.js | app.path() Function
- CSS clip-path Property
- D3.js path.toString() Function
- D3.js path.lineTo() Function
- Express.js req.path Property
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.
Improved By : Akanksha_Rai