How do I get a file extension in PHP?

前端 未结 28 2317
一向
一向 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:02

    pathinfo is an array. We can check directory name, file name, extension, etc.:

    $path_parts = pathinfo('test.png');
    
    echo $path_parts['extension'], "\n";
    echo $path_parts['dirname'], "\n";
    echo $path_parts['basename'], "\n";
    echo $path_parts['filename'], "\n";
    

提交回复
热议问题