要获取文件扩展名,可以使用PHP的pathinfo()函数或者explode()函数。
使用pathinfo()函数:
$file = 'example.txt';$ext = pathinfo($file, PATHINFO_EXTENSION);echo $ext; // 输出:txt使用explode()函数:
$file = 'example.txt';$ext = explode('.', $file);$ext = end($ext);echo $ext; // 输出:txt以上两种方法都可以获取文件的扩展名。

