GoodsController.class.php控制器页面
<?php
namespace Admin\Controller;
use Think\Controller;
class GoodsController extends Controller{
public function tianjia(){
$goods=D('Goods');
if(!empty($_POST)){
if($_FILES['f_goods_image']['error']<){
$cfg=array(
'rootPath' => './Public/uploadss/',
);//保存根路径
$up=new \Think\Upload($cfg);
$z= $up->uploadOne($_FILES['f_goods_image']);
// dump($up->getError());
//dump($z);
//把上传好的附件上传到数据库里面
$_POST['goods_big_img']= $up->rootPath .$z['savepath'].$z['savename'];
}
//收集表单
$shuju=$goods->create();
$z=$goods->add($shuju);
if($z){
$this->redirect('showlist',, '添加商品成功');
} else {
$this->redirect('tianjia',,'添加商品失败');
}
} else {
//展示表单
$this->display();
}
}
}