<!DOCTYPE html>//表单部分
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script>
function check(){
var name = document.form1.user_name;
var pwd1 = document.form1.pwd1;
var pwd2 = document.form1.pwd2;
if(name.value.length<6){
document.getElementById('name_msg').innerHTML="<font color='#FF0000'>用户名不得少于6个字符</font>";
// alert("用户名不得少于6个字符");
// name.focus();
return false;
}
if(pwd1.value.length<6){
document.getElementById("pwd1_msg").innerHTML="<font color='#FF0000'>密码不得少于6位数</font>";
pwd1.focus();
return false;
}
// if(pwd2.value.length<6){
// document.getElementById("pwd2_msg").innerHTML="密码不得少于6位数";
// pwd2.focus();
// return false;
// }
if(pwd1.value!==pwd2.value){
document.getElementById("pwd2_msg").innerHTML="<font color='#FF0000'>两次密码不一致</font>";
pwd2.focus;
return false;
}
return true;
}
function check1(){
var name = document.form1.user_name;
var pwd2 = document.form1.pwd2;
var pwd1 = document.form1.pwd1;
if(name.value.length<6){
document.getElementById('name_msg').innerHTML="<font color='#FF0000'>用户名不能少于6个字符</font>";
return false;
}else{
document.getElementById('name_msg').innerHTML="";
}
if(pwd1.value.length<6){
document.getElementById('pwd1_msg').innerHTML="<font color='#FF0000'>密码不能少于6个字符</font>";
return false;
}else{
document.getElementById('pwd1_msg').innerHTML="";
}
if(pwd1.value!==pwd2.value){
document.getElementById("pwd2_msg").innerHTML="<font color='#FF0000'>两次密码必须一致</font>";
pwd2.focus();return false;
}else{
document.getElementById("pwd2_msg").innerHTML="";
}
}
</script>
<pre>
<form name="form1" action="reg.php" method="post" onsubmit="check()" enctype="multipart/form-data"><br>
用 户 名:<input type="text" name="user_name" onblur="check1()" autofocus="autofocus"/><span id="name_msg"></span><br>
密 码:<input type="password" name="pwd1" onblur="check1()"/><span id="pwd1_msg"></span><br>
确认密码:<input type="password" name="pwd2" onblur="check1()"/><span id="pwd2_msg"></span><br>
头 像:<input type="file" name="img" />
邮 箱:<input type="text" name="email" /><span id="mail_msg"></span><br>
性 别:<input type="radio" name="sex" value="男" checked="checked"/>男<input type="radio" name="sex" value="女" />女<br>
<input type="submit" name="注册" /> <input type="reset" name="重置" /><br>
</form>
</pre>
</body>
</html>
<?php//表单接收
date_default_timezone_set('Etc/GMT');
echo "<meta charset='utf-8'>";
//接受参数
print_r($_POST);
$name=$_POST['user_name'];
$pwd1=$_POST['pwd1'];
$pwd2=$_POST['pwd2'];
$email=$_POST['email'];
$sex=$_POST['sex'];
$img=$_FILES['img'];
//print_r($img);
//echo $_FILES['img']['size'];
//exit;
//创建文件
@mkdir(date('Y'),0777);@mkdir(date('Y').'/'.date('m'),0777);@mkdir(date('Y').'/'.date('m').'/'.date('d'),0777);
//@touch(date('Y').'/'.date('m').'/'.date('d').'/'.info.php);
//判断
if(strlen($name)<6||strlen($pwd1)<6)echo "<script>history.back();alert('用户名或密码少于6个字符');</script>";
if($pwd1!==$pwd2)echo "<script>history.back();alert('两次密码不一致');</script>";
//判断图片的大小和格式
if($_FILES['img']['type']!=='image/jpeg'&&$_FILES['img']['type']!=='image/jpg'&&$_FILES['img']['type']!=='image/gif'&&$_FILES['img']['type']!=='image/png')
echo "<script>history.back();alert('图片格式不正确!');</script>";
if($_FILES['img']['size']>1024*1024)echo "<script>history.back();alert('图片不能超过2M!');</script>";
//上传图片
$hz = substr($img["name"], strrpos($img["name"],"."));
$newfile = time().rand(10000, 99999).$hz;
$doc = date('Y').'/'.date('m').'/'.date('d');
move_uploaded_file($img['tmp_name'], $doc.'/'.$newfile);
//录入数据库
$f=fopen($doc.'/'."info.txt", "a+");
$result=fwrite($f,$name."||".$pwd1."||".$pwd2."||".$email."||".$sex."
");
if($result!==FALSE){
echo "<script>history.back();alert('注册成功!');</script>";
}else{
echo "<script>history.back();alert('注册失败!');</script>";
}
fclose($f);
//$user_zl=file($f);
?>
<?php//txt接收的数据表格显示
date_default_timezone_set('Etc/GMT');
$doc = @date('Y').'/'.date('m').'/'.date('d');
if(!file_exists($doc.'/'."info.txt")){
echo "<p align='center' color='red'><font color='red'>今日暂时没有用户注册!</font></p>";
}else{
$filearr=@file($doc.'/'."info.txt");
foreach($filearr as $val){
$tmparr=explode("||", $val);
$newarr[]=$tmparr;
$tmparr=[];
}
echo '<table border="1" align="center">';
$i=1;
echo '<tr align="center"><th>序号</th><th>用户名</th><th>密码</th><th>确认密码</th><th>邮箱</th><th>性别</th></tr>';
foreach($newarr as $value){
echo "<tr align='center'><td>$i</td><td>$value[0]</td><td>$value[1]</td><td>$value[2]</td><td>$value[3]</td><td>$value[4]</td></tr>";
$i++;
}
echo '</table>';
}
?>