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



我试图在image crud类中添加固定高度-宽度的图像验证,但没有成功。下面尝试过,但没有奏效。未上传图像,但已完成数据库输入。

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'];
        }

}

注意:代码运行良好。但是错误应该发送到客户端。我认为这不是在图像crud中处理的。

我成功地添加了固定大小图像的验证。(正如我所质疑的那样,我走在了正确的轨道上,但下面的代码起了作用(。

在image_crud.php类中,第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;
  }

我认为您的代码中有一个圆括号,不可能存在。。。return 'masFileSize' 下方

更改此

if($width != 600 || $height != 800){
return 'maxFileSize';
}

if($width > 600 || $height > 800){
return 'maxFileSize';
}

最新更新