
//图片上传 js方法function save(){$.post("{$config['admin_route']}Jz/user_add",$('form').serialize(),function(res){switch (res.id) {case 0:layer.msg(res.msg,{'icon':2});break;case 1:layer.msg(res.msg,{'icon':1});setTimeout(function(){parent.window.location.reload();},1000);break;case 2:layer.msg(res.msg,{'icon':2});break;default:layer.msg(res.msg,{'icon':2});break;}},'json');}
public function user_add(){//用户添加//判断是否是post 提交 是的话再输出if (Request::isPost()) {$name = Request::post('name');$img = Request::post('test_img');//判断名称和头像是否为空if (empty($name) || empty($img) ) {echo json_encode(['id'=>2,'msg'=>'名称和图片不能为空']);return; //结束判断}else {//执行数据插入数据库$insert = Db::table('xmjz_user')->insert(['name' => $name,'img' => $img,'status' => 1]);}//判断是否插入成功,数据返回给前端if (!empty($insert)) {echo json_encode(['id' => 1,'msg'=>'成功']);}else {echo json_encode(['id'=>0,'msg'=>'失败']);}}else {return View::fetch();}}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号