GoodsController.class.php控制器页面
<?php
namespace AdminController;
use ThinkController;
class GoodsController extends Controller{
public function tianjia(){
$goods=D('Goods');
if(!empty($_POST)){
if($_FILES['f_goods_image']['error']<4){
$cfg=array(
'rootPath' => './Public/uploadss/',
);//保存根路径
$up=new ThinkUpload($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',3, '添加商品成功');
} else {
$this->redirect('tianjia',3,'添加商品失败');
}
} else {
//展示表单
$this->display();
}
}
}