php最大大小上传未正确验证

时间:2015-04-09 00:19:08

标签: php

if(!empty($employeepic)) {
    if ((($employeepic_type == 'image/jpg') ||($employeepic_type == 'image/jpeg') ||($employeepic_type == 'image/gif') ||
         ($employeepic_type == 'image/png')) && ($employeepic_size <= EMP_MAXSIZE) && ($employeepic_size > 0)){
        // Move the file to the target upload folder
        $target = (EMP_UPLOADPATH .$firstname.$employeepic);
        if(move_uploaded_file($_FILES['employeepic']['tmp_name'],$target)){
            $employee = $firstname. " " .$lastname;
        }
    }else{
        $filetoobig =' <p class="error"> There was a problem uploading your picture. Maximum size is 30K and must be in jpg, jpeg or pjpeg format</p>';
        @unlink($_FILES['employeepic']['tmp_name']);
    }
}

任何人都可以看到为什么文件大小的验证不起作用?

(EMP_MAXSIZE = 32768)

编辑:限制大小设置为32768但仍可上传2MB文件

修改:分配Employee_pic尺寸的代码:

$employeepic = mysqli_real_escape_string($dbc, trim($_FILES['employeepic']['name']));
$employeepic_type = $_FILES['employeepic']['type'];
$employeepic_size = $_FILES['employeepic']['size'];

1 个答案:

答案 0 :(得分:0)

我明白了。我可能没有做“正确的编码方式”,但它解决了问题。我创建了另一个名为$ employee_pic = $ firstname的变量。$ employeepic;在我的验证的真实部分,并添加了“employee_pic ='';”在我验证的错误结果下,为了不将图片保存到mysql。这是通过在我的插入查询中更改$ employee_pic的$ employeepic变量来完成的。