1-引入js文件和css文件
2-html代码
3-控制器
public function add() {
$file = $request->file("img");
//声明一个空的文件路径
$imgPath = "";
//移动文件到框架应用更目录的public/uploads/
if ($file) {
$info = $file->move(ROOT_PATH . 'public' . DS . 'upload' . DS . 'top_bar' . DS . date('Y') . DS . date('m-d'),md5(microtime(true)));
if ($info) {
$imgPath = "/public/upload/top_bar/" . date('Y') . '/' . date('m-d') . '/' . $info->getSaveName();
}
} else {
//错误提示用户
return $this->error($file->getError());
}
//赋值
$data["thumb_url"] = $imgPath;
$dataId = Db::name('top_bar')->insertGetId($data);
}