-3

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
Benny
  • 677
  • 1
  • 6
  • 22

3 Answers3

1

Read PATHINFO

$ext = pathinfo($filename, PATHINFO_EXTENSION);
Saty
  • 22,443
  • 7
  • 33
  • 51
1

You would use pathinfo()

$file = "path/to/file.png";
$ext = pathinfo($file, PATHINFO_EXTENSION);
baao
  • 71,625
  • 17
  • 143
  • 203
0

Check manual - pathinfo

Quick solution

$file_ext = pathinfo('your_file_name_here', PATHINFO_EXTENSION);
Kapil Sharma
  • 10,135
  • 8
  • 37
  • 66