[TIPS] Get File Extension Easily in PHP
Tuesday May 5, 2009 by Ivan Kristianto
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…
[TIPS] Solve WordPress Blank Page
[TIPS] Solving Ubuntu Sound Problem Without Restart



Thanks A Lot.
- spam
- offensive
- disagree
- off topic
Likethis is great!. Thanks a lot for sharing.
- spam
- offensive
- disagree
- off topic
LikeAnd don't forget about:
// code
$ext = pathinfo(__FILE__, PATHINFO_EXTENSION);
print $ext;
// end code
- spam
- offensive
- disagree
- off topic
LikeAnd don't forget about:
// code
$ext = pathinfo(__FILE__, PATHINFO_EXTENSION);
print $ext;
// end code
- spam
- offensive
- disagree
- off topic
Likewhat about
$filename = "f.i.l.e.ext";
print end(explode(".", $filename));
- spam
- offensive
- disagree
- off topic
Likewhat about
$filename = "f.i.l.e.ext";
print end(explode(".", $filename));
- spam
- offensive
- disagree
- off topic
LikeHi, nice posts there :-) thank's concerning the interesting advice
- spam
- offensive
- disagree
- off topic
LikeHi, nice posts there :-) thank's concerning the interesting advice
- spam
- offensive
- disagree
- off topic
LikeGreat tips! Thanks for sharing..
- spam
- offensive
- disagree
- off topic
LikeGreat tips! Thanks for sharing..
- spam
- offensive
- disagree
- off topic
Like