从php获取文件扩展名[duplicate]

This question already has an answer here:

I got the filename and path (gallery/thumbnail) where thumbnail can be png,jpg or mp4. it will always have the name "thumbnail" and i will always know the path.

How to find out what format the file is with php?

Edit.

I do not have the full file name (gallery/thumbnail.png) I only go the path without the extension (gallery/thumbnail.)

$fileName = "gallery/thumbnail.png' //file could be this
$fileName = "gallery/thumbnail.jpg"; //or this
$fileName = "gallery/thumbnail."; //but i only know this
</div>

Check manual - pathinfo

Quick solution

$file_ext = pathinfo('your_file_name_here', PATHINFO_EXTENSION);

Read PATHINFO

$ext = pathinfo($filename, PATHINFO_EXTENSION);

You would use pathinfo()

$file = "path/to/file.png";
$ext = pathinfo($file, PATHINFO_EXTENSION);