扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

php怎么获取文件扩展名

扬州沐宇科技
2023-11-02 11:01:10
PHP

要获取文件扩展名,可以使用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

以上两种方法都可以获取文件的扩展名。

扫码添加客服微信