
Model Layer Design
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;
}
}Accept the pictures sent from the hidden domain. If the picture is not an old picture, then delete the previous picture and then upload it again.