如何在php 5.6中添加图像大小验证

时间:2017-03-27 17:49:59

标签: javascript php html mysql php-5.6

我想在上传图片文件中添加限制。我想将大小验证为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);

1 个答案:

答案 0 :(得分:2)

您可以通过以下代码检查文件大小

// You should also check filesize here. 
if ($_FILES['uthu']['size'] > 500000) {
    $errors[] = "Exceeded filesize limit";
}