public function insert() { $upload = new \Think\Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $upload->rootPath = './Public'; $upload->savePath = './Uploads/'; $upload->autoSub = false; // 设置附件上传目录 // 上传文件 $info = $upload->upload(); if (!$info) { // 上传错误提示错误信息 $this->error($upload->getError()); } else { // 上传成功 $pic[0] = $info['gdetail_picname1']['savename']; $pic[1] = $info['gdetail_picname2']['savename']; $pic[2] = $info['gdetail_picname3']['savename']; $pic[3] = $info['gdetail_picname4']['savename']; } //创建信息操作对象 $gdetail = new \Think\Model("Gdetail"); //初始化添加数据(将POST中的添加信息加载到本对象中) $_POST['gdetail_picname1'] = $pic[0]; $_POST['gdetail_picname2'] = $pic[1]; $_POST['gdetail_picname3'] = $pic[2]; $_POST['gdetail_picname4'] = $pic[3]; $gdetail->create(); //执行添加 if ($gdetail->add()) { $this->success("添加成功!", U("Gdetail/index")); } else { $this->error("添加失败"); } }