Php 图像大小验证无效

Php 图像大小验证无效,php,Php,您好,我有一个验证检查我的表格,这是检查现有的图像,计数和 IF条件下的大小,但此处的图像大小验证不起作用 在我的代码中,我定义了用户只能上传500KB大小的六幅图像,但我现在就在这里 无法上载六幅图像,它们总共只有340KB 代码如下: $maxsize = '500000'; //Bytes $errors = array(); if (empty($_FILES['Upload_Property_Images']['name'][0]))

您好,我有一个验证检查我的表格,这是检查现有的图像,计数和

IF条件下的大小,但此处的图像大小验证不起作用

在我的代码中,我定义了用户只能上传500KB大小的六幅图像,但我现在就在这里

无法上载六幅图像,它们总共只有340KB

代码如下:

        $maxsize = '500000'; //Bytes    
        $errors = array();

    if (empty($_FILES['Upload_Property_Images']['name'][0])) 

    {
    $errors[] = 'You have not selected any image for uplaod field'; 
    }
    elseif ($_FILES['Upload_Property_Images']['size'] > $maxsize )

    {
    $errors[] = 'All six images must be less than 500 KB size'; 
    }

   else 
    {

    if (count($_FILES['Upload_Property_Images']['name']) !== 6)
        $errors[] = "-Your Only Allowed Six Images";


    $whitelist = array("jpg","png","JPG","PNG");

    foreach($_FILES['Upload_Property_Images']['name'] as $file) 
    {
        if ($file) 
        { 

            $temp = explode('.', $file);

            if (!in_array(end($temp), $whitelist )) 

            {
                $errors[] = "-All images must be JPG or PNG<br>";
                break;

            }
        }
    }
}
$maxsize='500000'//字节
$errors=array();
if(空($_文件['Upload_属性\u图像]['name'][0]))
{
$errors[]=“您尚未为uplaod字段选择任何图像”;
}
elseif($\u文件['Upload\u属性\u图像]['size']>$maxsize)
{
$errors[]=“所有六个图像的大小必须小于500 KB”;
}
其他的
{
如果(计数($_文件['Upload_Property_Images']['name'])!==6)
$errors[]=“-您只允许使用六个图像”;
$whitelist=数组(“jpg”、“png”、“jpg”、“png”);
foreach($\u文件['Upload\u属性\u图像]['name']作为$file)
{
如果($file)
{ 
$temp=explode('.',$file);
if(!in_数组(end($temp),$whitelist))
{
$errors[]=“-所有图像必须是JPG或PNG
”; 打破 } } } }
更新的代码片段

    $maxsize = '500000'; //Bytes    
    $errors = array();

if (empty($_FILES['Upload_Property_Images']['name'][0])) 

{
$errors[] = 'You have not selected any image for uplaod field'; 
}
elseif (array_sum($_FILES['Upload_Property_Images']['size']) > $maxsize )

{
$errors[] = 'All six images must be less than 500 KB size'; 
}

else 
{

if (count($_FILES['Upload_Property_Images']['name']) !== 6)
    $errors[] = "-Your Only Allowed Six Images";


$whitelist = array("jpg","png","JPG","PNG");

foreach($_FILES['Upload_Property_Images']['name'] as $file) 
{
    if ($file) 
    { 

        $temp = explode('.', $file);

        if (!in_array(end($temp), $whitelist )) 

        {
            $errors[] = "-All images must be JPG or PNG<br>";
            break;

        }
    }
}
}
$maxsize='500000'//字节
$errors=array();
if(空($_文件['Upload_属性\u图像]['name'][0]))
{
$errors[]=“您尚未为uplaod字段选择任何图像”;
}
elseif(数组\u和($\u文件['Upload\u属性\u图像]['size'])>$maxsize)
{
$errors[]=“所有六个图像的大小必须小于500 KB”;
}
其他的
{
如果(计数($_文件['Upload_Property_Images']['name'])!==6)
$errors[]=“-您只允许使用六个图像”;
$whitelist=数组(“jpg”、“png”、“jpg”、“png”);
foreach($\u文件['Upload\u属性\u图像]['name']作为$file)
{
如果($file)
{ 
$temp=explode('.',$file);
if(!in_数组(end($temp),$whitelist))
{
$errors[]=“-所有图像必须是JPG或PNG
”; 打破 } } } }
尝试回显此值“$\u FILES['Upload\u Property\u Images']['size']”&然后打印此条件的结果“($\u FILES['Upload\u Property\u Images']['size']>$maxsize)”@RohitBatra:I print但我没有得到任何值这里是打印代码:print$\u FILES['Upload\u Property\u Images']['size'];请尝试打印($\u文件),然后查看密钥是否存在?@RohitBatra:我得到了以下结果:数组([Upload\u Property\u Images]=>Array([name]=>Array([0]=>1.jpg[1]=>2.jpg[2]=>3.jpg[3]=>4.jpg[4]=>5.jpg)[type]=>Array([0]=>image/jpeg[1]=>image/jpeg[2]=>image/jpeg[3]=>image/jpeg[4]=>image/jpeg[4]=>tmu]>[0]0[0]0[0]0[0]0[0]0[0]0[0]0[0]0[0]0[0]0[2]2]0[2]2]=>C:\xampp\tmp[0]0[0]0[3]0]0[3]0]0[0]0[0]0[0]0[0]0]0[0]0]0]0[0]3]0]0[3]0]0]3]0]0[3]0]0]0[3]3]3]3]0[3]3]3]3]=>3]3]0[3]3]3]3]0[3]3]=>3]=>3]3]3[3]3]=>C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\C:\xampp>C:\xampp>C:\xampp>C:\xampp\0:\X罗希巴特拉:我现在该怎么办?