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

Posted 心之所依

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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];
}

以上是关于PHP实现获取文件后缀名的几种常用方法的主要内容,如果未能解决你的问题,请参考以下文章