php验证上传文件类型
在WEB应用中文件上传是系统不可少的功能,同时也存在很大安全隐患的地方,如果你没作限制就可以上传动态文件php,asp,jsp等,这样就对你的系统产生的特大的影响,下面我们来做二个验证上传文件类型.
第一种,代码如下:
<?php
function ($file_name, $pass_type=array('jpg','jpeg','gif','bmp','png')) {
$yx_file = $pass_type;
$kzm = substr(strrchr($file_name, ".") , 1);
$is_img = in_array(strtolower($kzm) , $yx_file);
if ($is_img) { //开源代码phprm.com
return true;
} else {
return false;
}
}
?>第二种,用getimagesize函数实例,这个相对比上面一个安全一些,代码如下:
<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
if (strtolowerr $type != 'gif') {
die('图片类型不对');
}
echo "<img src=\"img/flag.jpg\" $attr alt=\"example\" />";本文地址:http://www.phprm.com/scxz/fs4750.html
转载随意,但请附上文章地址:-)