PHP如何上传文件?

要求代码解释!只允许jpg,gif,大小为1m以下的上传!

$f_type=strtolower("swf,rar,jpg,zip,7z,iso,gif,exe,rmvb");//设置可上传的文件类型

if (!is_uploaded_file($file) || ($_FILES['photoupload']['size'] > 20000 * 1024 * 1024) )
{
$error = 'Please upload only files smaller than 2Mb!';
}
$f_name=$_FILES['photoupload']['name'];
$tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名
$tmp_type=strtolower($tmp_type);
if(!stristr($f_type,$tmp_type)){
$error="对不起,不能上传格式为:".$tmp_type."的文件:".$f_name;

}
if(move_uploaded_file($_FILES['photoupload']['tmp_name'], $uploadfile)){
$result['result'] = 'success';
$result['size'] =$f_name."文件上传成功";
}
else{
$result['result'] = 'failed';
$result['error'] =$f_name."上传失败";
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-11-19
用字符串分割得到后辍名,和$_FILES[name][size]得到文件大小,然后能if进行判断
第2个回答  2009-11-19
嗯 楼上还说的不错