Home > php教程 > php手册 > php获取上传文件名的文件类型

php获取上传文件名的文件类型

WBOY
Release: 2016-06-13 10:03:48
Original
2913 people have browsed it

php教程获取上传文件名的文件类型

$imgname = $_FILES["file"]["name"]; //获取上传的文件名称
$filetype = pathinfo($imgname, PATHINFO_EXTENSION);//获取后缀
$newname = date("Ymdhis").".".$filetype; //构建新名称

再看

$file = 'www.bKjia.c0m.gif';
echo getfix( $file );

//得到的值为gif 这种方法最简单也最实例了,好下面我们来看看方法二一种用substr读取扩展名方法

 

$file ='aaa.gif';
echo substr($file,strpos($file,'.')+1);

//方法三 还是用数组

$file = '111cn.gif';
$d111cn = explode('.',$file);
echo $d111cn[count($d111cn)-1];

function getfix($l1){
 return end(explode('.', $l1));
}

 

$extname=substr($upload_file_name,strpos($upload_file_name,".")+1);//获取文件扩展名

strpos() 函数返回字符串在另一个字符串中第一次出现的位置。如果没有找到该字符串,则返回 false。

 

更多详细内容请查看:http://www.bKjia.c0m/phper/21/358ad3dd52a90fd7894a1047adc80208.htm

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