当上传的图像大小超过 3MB 时,我想发出错误消息。这是我当前的代码。当图像超过 3MB 时,它会正确显示错误消息,但在没有上传图像时也会发出错误消息。我该如何解决?
//image check start
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 3072000))
//image check end
{
if($_FILES['file']['size'] > 0)
{
file uploading script
} else {
do nothing
}
} else {
error("Maximum image size exceeded or invalid file format.");
}