How to get file extension in php
In this article, we will tell you how to get a file extension in PHP. The file extension is most important for file validation. for example when you upload some file and then you need to file type validation. like image extension jpg, png, and gif and file extension zip, pdf, and doc.
Now, let’s discuss about that, there are many ways to get file extension in PHP, but some ways we shared so you can see the following below example.
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?php $ext = explode('.', $filename); echo $ext[1]; $ext = end(explode(".", $filename)); echo $ext; $ext = pathinfo($filename, PATHINFO_EXTENSION); echo $ext; $ext = substr($filename, strrpos($filename, '.', -1), strlen($filename)); echo $ext; ?> |
Please follow and like us: