php 上传文件实例 注册账号

注册界面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<h1>注册</h1>
<form action="wenjianchuli2.php" method="post" enctype="multipart/form-data">
    <div>用户名:<input type="text" name="uid" /></div>
    <div>密码:<input type="text" name="pwd" /></div>
    <div>姓名:<input type="text" name="name" /></div>
    <div>性别:<input type="text" name="sex" /></div>
    <div>头像:<input type="file" name="pic" /></div>
    <input type="submit" value="注册" />
</form>
</body>
</html>
View Code
<?php
include("DBDA.php");
$db=new DBDA();

//控制上传格式
if(($_FILES["pic"]["type"]=="image/jpeg"||$_FILES["pic"]["type"]=="image/png")&&$_FILES["pic"]["size"]<102400)
{
    //处理文件名
    $filename="./img/".date("YmdHis").$_FILES["pic"]["name"];
    
    //转编码格式
    $filename=iconv("UTF-8","gb2312",$filename);
    
    //判断文件是否存在
    if(!file_exists($filename))
    {
        //上传(保存)文件
        move_uploaded_file($_FILES["pic"]["tmp_name"],$filename);    
    }
}

//向数据库users添加一条数据

$uid=$_POST["uid"];
$pwd=$_POST["pwd"];
$name=$_POST["name"];
$sex=$_POST["sex"]=="男"?true:false;

$url="/".$filename;

$sql="insert into users values('{$uid}','{$pwd}','{$name}',{$sex},'{$url}')";

$db->Query($sql,0);

header("location:wenjianshangchuan3.php");
View Code

登陆界面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<form action="wenjianchuli3.php" method="post">
<h1>登陆</h1>
<div>用户名:<input type="text" name="uid" /></div>
<div>密码:<input type="password" name="pwd" /></div>
<input type="submit" value="登陆" />
</form>
</body>
</html>
View Code
<?php
session_start();

include("DBDA.php");
$db=new DBDA();

$uid=$_POST["uid"];
$pwd=$_POST["pwd"];

$sql="select count(*) from users where uid='{$uid}' and pwd='{$pwd}'";

$zhi=$db->StrQuery($sql);

if($zhi>0)
{
    $_SESSION["uid"]=$uid;
    header("location:wenjianshangchuan4.php");    
}
else
{
    echo"登录失败";    
}
View Code

个人资料界面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<?php
session_start();

if(empty($_SESSION["uid"]))
{
    header("location:wenjianshangchuan3.php");    
    exit;
}

$uid=$_SESSION["uid"];

include("DBDA.php");
$db=new DBDA();

$sql = "select * from users where uid='{$uid}'";
$attr = $db->Query($sql);
?>
<body>
<div>
<div>用户名:<?php echo $attr[0][0] ?></div>
<div>密码:<?php echo $attr[0][1] ?></div>
<div>姓名:<?php echo $attr[0][2] ?></div>
<div>性别:<?php echo $attr[0][3]?"男":"女" ?></div>
<div>头像:<img src="<?php echo $attr[0][4] ?>" width="200" height="200" /></div>
</div>

</body>
</html>
View Code
原文地址:https://www.cnblogs.com/bilibiliganbei/p/5631302.html