Reka bentuk lapisan model
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; } }
Menerima gambar yang dihantar dari domain tersembunyi Jika gambar itu bukan gambar lama, kemudian padamkan gambar sebelumnya dan kemudian muat naik semula.