要获取文件扩展名,可以使用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
以上两种方法都可以获取文件的扩展名。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:php如何获取文件扩展名