品牌缩略图修改

QQ截图20170628163332.png

模型层设计

 public function _before_update(&$data,$option){
        if($_FILES['brand_logo']['tmp_name']){
            if($data['oldlogo']){
               if(file_exists($data['oldlogo'])){
                    @unlink($data['oldlogo']);
               }
            }

            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     3145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->autoSub = false;
            $upload->savePath  =      './Public/Uploads/Brand/'; // 设置附件上传目录
            $upload->rootPath  =      './';
            $info   =   $upload->uploadOne($_FILES['brand_logo']);
            $logo=$info['savepath'].$info['savename'];
            $image = new \Think\Image();
            $image->open($logo);
            $image->thumb(100, 30)->save($logo);
            $data['brand_logo']=$logo;
        }
    }

接受隐藏域发送过来的图片,如果图片不是老图的话,那么就将之前的图片删除,然后再上传。


继续学习
||
public function _before_update(&$data,$option){ if($_FILES['brand_logo']['tmp_name']){ if($data['oldlogo']){ if(file_exists($data['oldlogo'])){ @unlink($data['oldlogo']); } } $upload = new \Think\Upload();// 实例化上传类 $upload->maxSize = 3145728 ;// 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型 $upload->autoSub = false; $upload->savePath = './Public/Uploads/Brand/'; // 设置附件上传目录 $upload->rootPath = './'; $info = $upload->uploadOne($_FILES['brand_logo']); $logo=$info['savepath'].$info['savename']; $image = new \Think\Image(); $image->open($logo); $image->thumb(100, 30)->save($logo); $data['brand_logo']=$logo; } }
提交重置代码