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是您要寻找的

PHP.net

$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;
}