Alex Rivera | Logout

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

Asked 2010-07-05T12:02:37.720
12

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

Edit
Report

2 Answers

1

As Col. Shrapnel mentioned; there's quite a few ways

$path = '/some/where/img.gif';
$path = explode('.',$path);
$path = end($path);
answered 2010-07-05T12:06:53.897
-2

Basic string functions, strrpos() and substr() can do that for you. As well as many other fancy ways.

answered 2010-07-05T12:04:31.903

Your Answer