Home > php教程 > php手册 > body text

PHP中获取文件扩展名程序代码

WBOY
Release: 2016-06-13 10:15:51
Original
1285 people have browsed it

在php中有时我们想获得上传文件的扩展名,下面我来总结了在php中扩展名获取方法总结,有需要的朋友可参考。

方法一,我自己最的一种获取扩展名方法

 代码如下 复制代码

function extend_2($file_name)
{
$extend = pathinfo($file_name);
$extend = strtolower($extend["extension"]);
return $extend;
}

方法二,利用explode函数与end函数组合操作

 代码如下 复制代码

function get_extension($file)
{
return end(explode('.', $file));
}


方法三,就是像以前在asp中获取扩展名一样的做法。

 代码如下 复制代码

function get_extension($file)
{
substr(strrchr($file, '.'), 1);
}


好了方法就这三种了,基本来满足的你获取文件扩展名了。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!