• 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
  • 相关阅读:
    javascript之全局函数
    讲真,MySQL索引优化看这篇文章就够了
    aws亚马逊磁盘扩展卷步骤
    google支付回调验证(备用)
    Linux TCP状态TIME_WAIT 过多的处理
    MySQL索引优化分析
    CSS使图片变模糊,亲测非常好用
    linux ss 命令用法说明
    php一行代码获取本周一,本周日,上周一,上周日,本月一日,本月最后一日,上月一日,上月最后一日日期
    有哪些你追了很多女生才明白的道理?
  • 原文地址:https://www.cnblogs.com/bilibiliganbei/p/5631302.html
Copyright © 2020-2023  润新知