改进验证类的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)) { if (!($file instanceof File)) {
return false; return false;
} }
$rule = explode(',', $rule); if ($rule) {
list($width, $height, $type) = getimagesize($file->getRealPath()); $rule = explode(',', $rule);
if (isset($rule[2])) { list($width, $height, $type) = getimagesize($file->getRealPath());
$imageType = strtolower($rule[2]); if (isset($rule[2])) {
if ('jpeg' == $imageType) { $imageType = strtolower($rule[2]);
$imageType = 'jpg'; if ('jpeg' == $imageType) {
} $imageType = 'jpg';
if (image_type_to_extension($type, false) != $imageType) { }
return false; 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;
} }
/** /**