PHP实现获取文件后缀名的几种常用方法

方法1:

function get_file_type($filename){
$type = substr($filename, strrpos($filename, ".")+1);
return $type;
} 方法2: function get_file_type($filename)
{
$type = pathinfo($filename);
$type = strtolower($type["extension"]);
return $type;
} 方法3: function get_file_type($filename)
{
$type =explode("." , $filename);
$count=count($type)-1;
return $type[$count];
}
方法4:

function getExt1($filename)
{
$arr = explode('.',$filename);
return array_pop($arr);;
} 方法5: function getExt2($filename)
{
$ext = strrchr($filename,'.');
return $ext;
} 方法6:
function getExt3($filename)
{
$pos = strrpos($filename, '.');
$ext = substr($filename, $pos);
return $ext;
} 方法7: function getExt4($filename)
{
$arr = pathinfo($filename);
$ext = $arr['extension'];
return $ext;
} 方法8: function getExt5($filename)
{
$str = strrev($filename);
return strrev(strchr($str,'.',true));
}

 
上一篇:react-native 编译报错: undefined is not an object (evaluating '_react2.PropTypes.func')


下一篇:自定义input文件上传样式