【问题标题】:How to add Image Size validation in php 5.6如何在 php 5.6 中添加图像大小验证
【发布时间】:2017-08-20 13:31:31
【问题描述】:

我想在上传图像文件中添加限制。我想验证大小为 500kb。这是我的代码。

if(empty($_FILES["uthu"]["name"])) $errors[] = "拇指为空"; if($_FILES["uthu"]["error"] != 0) $errors[] = "上传缩略图出错"; $ext = strtolower(substr($_FILES["uthu"]["name"], -4)); if($ext != ".jpg") $errors[] = "为 Thumb 上传 .jpg"; $fnm1 = time().rand(1111,9999)."_".$_FILES["uthu"]["name"]; move_uploaded_file($_FILES["uthu"]["tmp_name"], "uploads/".$fnm1);

【问题讨论】:

标签: javascript php html mysql php-5.6


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2014-01-09
    • 2012-02-14
    • 2020-05-08
    • 2018-12-22
    • 1970-01-01
    • 2014-09-16
    • 2015-06-11
    • 2020-08-27
    • 1970-01-01
    相关资源
    最近更新 更多