Is there any standard function in PHP to find only extension of an image from the corresponding file path?
For example ff my image path is like '/testdir/dir2/image.gif' then the function should return 'gif'.
Thanks
PNG'; $ext = strtolower(pathinfo($src_file_name, PATHINFO_EXTENSION)); // Using strtolower to overcome case sensitive if (in_array($ext, $supported_image)) { echo "it's image"; } else { echo 'not image'; } ?>
$extension = pathinfo ( $file_name , PATHINFO_EXTENSION); echo $extension ; ?> Using end() function: It explodes the file variable and gets the last array element to be the file extension.
$ext = pathinfo(
parse_url('/testdir/dir2/image.gif?foo=bar', PHP_URL_PATH),
PATHINFO_EXTENSION
); //$ext will be gif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With