我想在上传图片文件中添加限制。我想将大小验证为500kb。这是我的代码。
if(empty($_FILES["uthu"]["name"])) $errors[] = "Thumb was empty"; if($_FILES["uthu"]["error"] != 0) $errors[] = "error uploading Thumbnail"; $ext = strtolower(substr($_FILES["uthu"]["name"], -4)); if($ext != ".jpg") $errors[] = "upload .jpg for Thumb"; $fnm1 = time().rand(1111,9999)."_".$_FILES["uthu"]["name"]; move_uploaded_file($_FILES["uthu"]["tmp_name"], "uploads/".$fnm1);
答案 0 :(得分:2)
您可以通过以下代码检查文件大小
// You should also check filesize here.
if ($_FILES['uthu']['size'] > 500000) {
$errors[] = "Exceeded filesize limit";
}