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 = hinkImage::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 = hinkImage::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 "失败"; } }