Get the file extension of a file using PHP
Posted on Thursday, December 02nd (2302 days ago)
Using PHP, getting the file extension (i.e. the “.jpg” part of the file name) of a file pretty easy:
$ext = substr(strrchr($filename, '.'), 1);
This is useful for instances where you need to create an image tag in your HTML and you don’t know what the file extension is going to be, or if different file type require different attributes etc.
About Joseph R. B. Taylor
Joseph R. B. Taylor is a designer/developer who makes stuff for screens of all shapes and sizes. He currently works at Edvisors, Inc. where he creates screen-based experiences for used by millions of college students every year.