How do I get a file extension in PHP?

前端 未结 28 2249
一向
一向 2020-11-21 22:45

This is a question you can read everywhere on the web with various answers:

$ext = end(explode(\'.\', $filename));
$ext = substr(strrchr($filename, \'.\'), 1         


        
28条回答
  •  鱼传尺愫
    2020-11-21 23:20

    As long as it does not contain a path you can also use:

    array_pop(explode('.', $fname))
    

    Where $fname is a name of the file, for example: my_picture.jpg. And the outcome would be: jpg

提交回复
热议问题