In this article, we will tell you how to get 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.
<?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: