PHP检查文件扩展名 [英] PHP check file extension
本文介绍了PHP检查文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个上传脚本,需要检查文件扩展名,然后基于该文件扩展名运行单独的功能.有人知道我应该使用什么代码吗?
I have an upload script that I need to check the file extension, then run separate functions based on that file extension. Does anybody know what code I should use?
if (FILE EXTENSION == ???)
{
FUNCTION1
}
else if
{
FUNCTION2
}
推荐答案
pathinfo
是您要寻找的
$file_parts = pathinfo($filename);
switch($file_parts['extension'])
{
case "jpg":
break;
case "exe":
break;
case "": // Handle file extension for files ending in '.'
case NULL: // Handle no file extension
break;
}
这篇关于PHP检查文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文