PHP有判断文件类型的函数
<?PHP
/*
函数说明:判断文件是不是在指定的文件类型中
参数:$file 要判断的文件名称
参数:$type 正确的文件类型,多种类型用"|"分开
*/function file_type($file,$type){
return eregi("\.($type)$",$file);
}if(file_type("index.php","htm|html|jpg|gif"))
echo "错误,不被允许的文件类型";
else echo"该文件可以上传";
?>
<?PHP
/*
函数说明:判断文件是不是在指定的文件类型中
参数:$file 要判断的文件名称
参数:$type 正确的文件类型,多种类型用"|"分开
*/function file_type($file,$type){
return eregi("\.($type)$",$file);
}if(file_type("index.php","htm|html|jpg|gif"))
echo "错误,不被允许的文件类型";
else echo"该文件可以上传";
?>
解决方案 »
- php输出html时转义
- 网络安全师的前景怎么样
- html,php等的文件头问题
- php写xml文件,问题奇怪!!请高手帮忙!!!
- 求助:本人看上一個 OA精靈。
- 有谁知道php怎么和注册表联系起来 听说 冰冰的 iNews 就有一个注册表文件,没有那个文件程序运行出错。
- 在使用nusoap写web service时,发现耗费cpu资源极高
- phpMyAdmin为什么连不上?
- HTTP 错误 500.0 - Internal Server Error
- ubuntu 不能正确配置php环境
- 大家帮忙看一下这样的网站一般做下来最低的多少钱谢谢各位
- php 存储 sqlserver 数据库 image 子段 有问题!!!!!?帮帮忙,十万火急!
access
-------------
abc.doc
apple.jpg
sadasdsa.gif
polo.123.jpg
abnn怎样根据扩展名判断啊? 注意,例如上面的polo.123.jpg,如果判断了123就错误了。就是判断最后的小数点之后的扩展名是否jpg或者gif,是就...,否则就...
<?PHP
$type ="bmp|png|jpg|gif";
$filename="polo.123.jpg";
function file_type($file,$type){
return eregi("\.($type)$",$file);
}
if(file_type($filename,$type)){
echo "是图片";
}else{echo"不是图片";}
?>
$filename = "D:\\296.mid";
$file = fopen($filename, "rb");
$bin = fread($file, 2); //只读2字节
fclose($file);
$strInfo = @unpack("c2chars", $bin);
$typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
$fileType = '';
switch ($typeCode)
{
case 7790:
$fileType = 'exe';
break;
case 7784:
$fileType = 'midi';
break;
case 8297:
$fileType = 'rar';
break;
case 255216:
$fileType = 'jpg';
break;
case 7173:
$fileType = 'gif';
break;
case 6677:
$fileType = 'bmp';
break;
case 13780:
$fileType = 'png';
break;
default:
echo 'unknown';
}
echo 'this is a(an) '.$fileType.' file:'.$typeCode;
?>