改进验证类的image方法

This commit is contained in:
thinkphp
2016-10-21 17:51:19 +08:00
parent 35a12fac90
commit 294a49b8b1

View File

@@ -723,19 +723,24 @@ class Validate
if (!($file instanceof File)) {
return false;
}
$rule = explode(',', $rule);
list($width, $height, $type) = getimagesize($file->getRealPath());
if (isset($rule[2])) {
$imageType = strtolower($rule[2]);
if ('jpeg' == $imageType) {
$imageType = 'jpg';
}
if (image_type_to_extension($type, false) != $imageType) {
return false;
if ($rule) {
$rule = explode(',', $rule);
list($width, $height, $type) = getimagesize($file->getRealPath());
if (isset($rule[2])) {
$imageType = strtolower($rule[2]);
if ('jpeg' == $imageType) {
$imageType = 'jpg';
}
if (image_type_to_extension($type, false) != $imageType) {
return false;
}
}
list($w, $h) = $rule;
return $w == $width && $h == $height;
} else {
return in_array($this->getImageType($file->getRealPath()), [1, 2, 3, 6]);
}
list($w, $h) = $rule;
return $w == $width && $h == $height;
}
/**