public function AddNews(){
$data = Request::instance()->param();
//接收文件
$file = request()->file('img');
//上传
$info = $file->move(ROOT_PATH . 'public' . DS . 'static' . DS . 'uploads');
if($info){
//获取文件名字
$path = $info->getSaveName();
//拼接一下图片绝对路径
$last_path = ROOT_PATH . 'public' . DS . 'static' . DS . 'uploads'.DS.$path;
}else{
$path = null;
$last_path = null;
}
if($last\_path){
//打开原图
$image = \\think\\Image::open($last\_path);
//生成缩略图
$thumb\_path = rand().'.jpg';
$image->thumb(10, 10)->save(ROOT\_PATH . 'public' . DS . 'static' . DS .'thumb'.DS.$thumb\_path);
}
if($last\_path){
//打开图片
$image = \\think\\Image::open($last\_path);
//生成水印
$water\_path = ROOT\_PATH . 'public' . DS . 'static' . DS .'waters'.DS.rand().'.jpg';
$image->text('刘桂池',ROOT\_PATH . 'public' . DS .'ttf'.DS.'fangzheng.ttf',20,'#00000')->save($water\_path);
}
//拼接数据入库
$arr\['title'\] = $data\['title'\];
$arr\['t\_name'\] = $data\['t\_name'\];
$arr\['img'\] = $path;
$arr\['content'\] = $data\['news\_content'\];
$arr\['thumb'\] = empty($thumb\_path)? null : $thumb\_path;
if(Db::table('d13')->insert($arr)){
echo "成功";
}else{
echo "失败";
}
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章