Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the extension of an image from path in PHP?

Tags:

php

image

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

like image 940
Siva Avatar asked Jul 05 '10 12:07

Siva


People also ask

How do I find out the extension of an image?

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'; } ?>

How can I get file extension in PHP?

$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.


1 Answers

$ext = pathinfo(
    parse_url('/testdir/dir2/image.gif?foo=bar', PHP_URL_PATH), 
    PATHINFO_EXTENSION
); //$ext will be gif
like image 135
fabrik Avatar answered Oct 13 '22 23:10

fabrik