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…