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.
$ext = explode('.', $filename);
$ext = end(explode(".", $filename));
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$ext = substr($filename, strrpos($filename, '.', -1), strlen($filename));