-2

What is the simple way to find the file extension in php, if the filename is filename.jpg.txt?

nithi
  • 3,725
  • 2
  • 20
  • 18
  • 3
    you think this has never been asked before? did you search? can you see the *related* list on the right? –  Apr 24 '12 at 10:07

3 Answers3

4

you can use the pathinfo function that will provide useful info about the file path, including the extension

http://php.net/pathinfo

mishu
  • 5,347
  • 1
  • 21
  • 39
0

You can try splitting the string with explode(".", $string); and then checking the last element of the array that is returned.

ikromm
  • 523
  • 6
  • 13
0
function file_extension($filename)
{
    $path_info = pathinfo($filename);
    return $path_info['extension'];
}

Use this function get the file's actual type

BenMorel
  • 34,448
  • 50
  • 182
  • 322
arun
  • 3,667
  • 3
  • 29
  • 54