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 "失敗"; } }