代码如下:
<?php /** * 判断上传文件大小 * edit www.jb200.com */ function imageUpload() { if (is_uploaded_file($_FILES['logo']['tmp_name'])) { //$_FILES是一个关于图片信息的数组 $upfile = ($_FILES["logo"]); //赋值 $suffix=substr($upfile["name"],strrpos($upfile["name"],".")); $name = mktime() .rand().$suffix; //原文件名 $type = $upfile["type"]; //文件类型 $size = $upfile["size"]; //文件大小 $tmp_name = $upfile["tmp_name"]; //临时文件名 $error = $upfile["error"]; //上传相关错误代码 $str=getimagesize($tmp_name); $mode="/width="(.*)" height="(.*)"/"; preg_match($mode,$str[3],$arr); if($arr[1]>120 || $arr[2]>60){ echo "<script>alert('图片过大');</script>"; exit(); } switch ($type) { case 'image/pjpeg' : $ok = 1; break; case 'image/jpeg' : $ok = 1; break; case 'image/gif' : $ok = 1; break; //case 'image/x-png' : // $ok = 1; //IE为x-png;FOX为png // break; } if ($ok && $error == '0') { move_uploaded_file($tmp_name, "c:/" . $name); return $name; } } else { return null; } } ?>