品牌縮圖修改

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; } }
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!