PHP string get file extension

墨辰丷
Release: 2023-03-29 21:34:01
Original
1175 people have browsed it

This article mainly introduces the PHP string to obtain the file extension. Interested friends can refer to it. I hope it will be helpful to everyone.

The code is as follows:

$filename="123.jpg";
//方法一:
function get_ext($file_name){
  return array_pop(explode('.', $file_name));
  //用.号对字符串进行分组
}
echo get_ext($filename);
//方法二:
$fileEx=strtolower(substr(strrchr($filename,"."),1));
echo $fileEx;
//方法三:
$extend=pathinfo($filename);
echo $extend['extension'];
//方法四:
$filetype=array("image/gif","image/jpeg");
//判断文件扩展名类型是否在该 数组中
if(in_array($_FILES['file']['type'],$filetype)){
//针对上传文件判断
  echo $_FILES['file']['type'];
}
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

php method to obtain the number of file lines

php external execution command function usage summary

php Detailed explanation of infinite classification tree data formatting code example

The above is the detailed content of PHP string get file extension. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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 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!