PHP get file name with extension

Last updated on November 17th, 2015 at 05:16 am

Click to rate this tutorial!
[Total: 4 Average: 4.3]

The script below will help using PHP to get file name with extension. We are using function named pathinfor(), filenames well as the directory name.This functions returns the path information in a array with the following elements dirname, basename and extension. Let’s look at the example of pathinfo() function first

< ?php
 $myweb = pathinfo('/root/websitename/index.html');
 echo $myweb['basename'], "<br />";
 echo $myweb['extension'], "<br />";
 echo $myweb['dirname'], "<br />";
?>

Let output of the above will be
index.html – This is file name
html – This is extension
/root/websitename/ –This is directory name

PATHINFO() -> http://www.php.net/pathinfo

Click to rate this tutorial!
[Total: 4 Average: 4.3]

Leave a Reply

Your email address will not be published.