image crud 需要为固定大小的图片上传添加验证,例如仅 600 x 800

image crud need to add validation for fixed size image upload e.g. 600 x 800 only

我正在尝试在图像增删改查中添加固定高度宽度的图像验证 class 但没有成功。在下面尝试但没有用。图片未上传,但数据库条目已完成。

class ImageUploadHandler
{

========

private function has_error($uploaded_file, $file, $error) {



if ($uploaded_file && is_uploaded_file($uploaded_file)) {
            $file_size = filesize($uploaded_file);

list($width, $height, $type, $attr) = getimagesize($uploaded_file);

if($width != 600 || $height != 800){

return 'maxFileSize';

}

        } else {
            $file_size = $_SERVER['CONTENT_LENGTH'];
        }



}

注意:代码运行良好。但错误应该发送到客户端。我认为它没有在 image-crud 中处理。

我认为您的代码中有一个不应该存在的括号...就在 return 'masFileSize'

下方

改这个

if($width != 600 || $height != 800){

return 'maxFileSize';

}

if($width > 600 || $height > 800){

return 'maxFileSize';

}

我成功地为固定大小的图像添加了验证。(正如我所说的那样,我走在正确的轨道上,但下面的代码有效)。

在image_crud.phpclass行号。 333.

 list($width, $height) = getimagesize($path);
 if($width != $this->max_width || $height != $this->max_height)
 {                 
 /* Commented below line */         
  //$ci->image_moo->load($path)->resize($this->max_width,$this->max_height)->save($path,true);
    //and returned false
    return false;
  }