代码拉取完成,页面将自动刷新
<?php
include_once('config/config.php');
$LoginAdmin = checkAuth();
if($LoginAdmin['id'] != 1){
showMsg('暂无权限','admin.php');
}
if($_POST)
{
if(empty(trim($_POST['username']))){
showMsg('管理员昵称不能为空!');
}
if(empty(trim($_POST['password']))){
showMsg('密码不能为空!');
}
if(empty(trim($_POST['repass']))){
showMsg('确认密码不能为空!');
}
if(trim($_POST['password'] != trim($_POST['repass']))){
showMsg('密码与确认密码不一致!');
}
// 生成密码盐
$salt = build_ranstr();
$password = md5($_POST['password'] . $salt);
//封装数据
$data = array(
"username" => trim($_POST['username']),
"password" => $password,
"salt" => $salt
);
// 处理头像数据
$avatar = build_upload('avatar');
if($avatar['code'] === 0){
showMsg($avatar['msg']);
}
$data['avatar'] = $avatar['data'];
// 插入数据
$result = add('admin',$data);
if($result['code'] === 0){
showMsg($result['msg']);
}else{
showMsg($result['msg'],'admin.php');
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include_once('common/meta.php'); ?>
</head>
<style>
input[type="file"]{
display: none;
}
label[for="avatar"]
{
width: 200px;
}
</style>
<body>
<?php include_once('common/header.php');?>
<?php include_once('common/menu.php') ?>>
<div class="content">
<div class="header">
<h1 class="page-title">添加管理员</h1>
</div>
<ul class="breadcrumb">
<li><a href="admin.php">admin</a> <span class="divider">/</span></li>
<li class="active">adminAdd</li>
</ul>
<div class="container-fluid">
<div class="row-fluid">
<div class="well">
<div id="myTabContent" class="tab-content">
<div class="tab-pane active in" id="home">
<form method="post" enctype="multipart/form-data">
<label>昵称</label>
<input type="text" name="username" placeholder="请输入管理员昵称" class="input-xxlarge">
<label>密码</label>
<input type="password" name="password" placeholder="请输入密码" class="input-xxlarge">
<label>确认密码</label>
<input type="password" name="repass" placeholder="请输入确认密码" class="input-xxlarge">
<label>头像</label>
<label for="avatar">
<img src="/assets/images/upload.png" id="upload" alt="">
</label>
<input type="file" name="avatar" id="avatar" class="input-xlarge">
<label></label>
<input class="btn btn-primary" type="submit" value="提交" />
</form>
</div>
</div>
</div>
<?php include_once('common/footer.php'); ?>
</div>
</div>
</div>
</body>
</html>
<?php include_once('common/script.php'); ?>
<script>
// 图片预览
$('#avatar').change(function(){
let file = $(this)[0].files[0];
if(file)
{
let reader = new FileReader();
reader.readAsDataURL(file)
// 事件
reader.onload = function()
{
$('#upload').attr('src',reader.result);
}
}
});
</script>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。