示例#1
0
 public function update($goods_id)
 {
     $goods = new \Model\GoodsModel();
     if (!empty($_POST)) {
         if ($_FILES['goods_img']['error'] === 0) {
             $cfg = array('rootPath' => './Admin/Public/goods/');
             $up = new \Think\Upload($cfg);
             $z = $up->uploadOne($_FILES['goods_img']);
             $_POST['goods_big_img'] = $up->rootPath . $z['savepath'] . $z['savename'];
             $bigimg = $_POST['goods_big_img'];
             //对上传图片进行缩略图处理
             $im = new \Think\Image();
             //实例化对象
             $im->open($bigimg);
             //相对服务器路径打开图片
             $im->thumb(165, 165, 3);
             //自适应大小制作缩略图
             $smallimg = $up->rootPath . $z['savepath'] . "small_" . $z['savename'];
             $im->save($smallimg);
             //保存
             $_POST['goods_small_img'] = $smallimg;
             //var_dump($_POST['goods_big_img']);die;
         }
         $arr = $goods->create();
         $result = $goods->save($arr);
         if ($result) {
             $this->redirect('showlist', array(), 2, '修改商品成功');
         } else {
             var_dump($goods->getError());
         }
     }
     $category = new \Model\CategoryModel();
     $cats = $category->select();
     $this->assign('cats', $cats);
     $info = $goods->find($goods_id);
     $this->assign('info', $info);
     $this->display();
 }