-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
  • 507
  • 3
  • 18

3 Answers3

0

Check manual - pathinfo

Quick solution

$file_ext = pathinfo('your_file_name_here', PATHINFO_EXTENSION);
Kapil Sharma
  • 9,676
  • 8
  • 36
  • 64
0

Read PATHINFO

$ext = pathinfo($filename, PATHINFO_EXTENSION);
Saty
  • 22,213
  • 7
  • 30
  • 49
0

You would use pathinfo()

$file = "path/to/file.png";
$ext = pathinfo($file, PATHINFO_EXTENSION);
baao
  • 67,185
  • 15
  • 124
  • 181