如何在PHP中获取文件扩展名? [英] How to get the file extension in PHP?

查看:97
本文介绍了如何在PHP中获取文件扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望获取要上传的图像的文件扩展名,但我只获得了一个数组.

I wish to get the file extension of an image I am uploading, but I just get an array back.

$userfile_name = $_FILES['image']['name'];
$userfile_extn = explode(".", strtolower($_FILES['image']['name']));

有没有办法直接获得扩展名?

Is there a way to just get the extension itself?

推荐答案

无需使用字符串函数.您可以使用实际为您想要的东西而设计的东西: pathinfo() :

No need to use string functions. You can use something that's actually designed for what you want: pathinfo():

$path = $_FILES['image']['name'];
$ext = pathinfo($path, PATHINFO_EXTENSION);

这篇关于如何在PHP中获取文件扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆