I want to share a tips for you to get file extension in PHP easily. Before i always use the old way to get the file extension, that is using substring and find the last “.” (dot), and get the extension. For those who still doing this, i have a tips for you to get the extension easier.
You can use pathinfo, with pathinfo you can get information about a file path, here is the example how to use it:
<?php $fileinfo = pathinfo("/path/to/your/file.php"); echo $fileinfo['dirname']; // Get directory echo $fileinfo['basename']; // Get file basename echo $fileinfo['extension']; // Get file extension echo $fileinfo['filename']; // Get file name ?>
That’s it! Thank you for visiting my blog and have a nice day…
Great tips! Thanks for sharing..
Great tips! Thanks for sharing..
Hi, nice posts there 🙂 thank's concerning the interesting advice
Hi, nice posts there 🙂 thank’s concerning the interesting advice
what about
$filename = "f.i.l.e.ext";
print end(explode(".", $filename));
what about
$filename = “f.i.l.e.ext”;
print end(explode(“.”, $filename));
And don't forget about:
// code
$ext = pathinfo(__FILE__, PATHINFO_EXTENSION);
print $ext;
// end code
And don’t forget about:
// code
$ext = pathinfo(__FILE__, PATHINFO_EXTENSION);
print $ext;
// end code
this is great!. Thanks a lot for sharing.
Thanks A Lot.