php留言板个人中心

1、个人中心显示当前登陆用户的信息和实现头像上传功能

源码如下:

<!DOCTYPE html>
<html>
<head>
	<title>个人中心</title>
<meta charset="utf-8">





</head>
<body>
<?php
include "conn.php";
$uid = $_GET["uid"];//留言板页面通过session传过来的uid
//echo $uid;
$sql = "select * from user where uid=$uid";
$result = mysqli_query($conn,$sql);
$persion = mysqli_fetch_array($result);
?>
<center>
<form action="pic.php" method="post" enctype="multipart/form-data">
<table border="1" cellpadding="4">


<tr>                       <!--设置文件头像上传-->
<td align="center" colspan="2"><?php echo "<img src='".$persion['picture']."' width='50' higth='50'>";?></td>
</tr>
<td colspan="2"><input type="file" name="file"><input type="submit" name="submit" value="提交"></td>
<input type="hidden" name="uid" value="<?php echo $uid;?>"></td>
<tr>
<td>用户名</td>
<td><?php echo $persion["username"]; ?></td><!--输出当前登陆用户的信息-->
</tr>
<td>邮箱</td>
<td><?php echo $persion["email"]; ?></td>
</tr>
<td>性别</td>
<td><?php echo $persion["sex"]; ?></td>
</tr>
<td>时间</td>
<td><?php  echo date("Y-m-d");?></td>
</tr>
</form>
</table>





</body>
</html>

效果图:

2、头像上传

源码如下:

<meta charset="utf-8">
<?php
    include "conn.php";
    //echo $_FILES['file']['name'] . "<br/>";
    //echo $_FILES['file']['type'] . "<br/>";
    //echo $_FILES['file']['tmp_name'] . "<br/>";
    //echo $_FILES['file']['size'] . "<br/>";
    //echo $_FILES['file']['error'] . "<br/>";

    $path = "./image/";
    $uid = $_POST["uid"];
    if (!is_dir($path))
     {
      mkdir($path);
    }

    $mime =  $_FILES['file']['type'];
    if (($mime == "image/jpeg") || ($mime == "image/gif") || ($mime == "image/png") && ($_FILES['file']['error'] == 0))
    {
      $filename = $path . $_FILES['file']['name'];
      move_uploaded_file($_FILES['file']['tmp_name'], $filename);

      $sql = "update user set picture = '$filename' where uid = $uid";
      $result = mysqli_query($conn,$sql);
      if ($result)
      {
        echo "<script>alert('头像上传成功!')</script>";
            echo "<script>window.location.href=\"pcenter.php?uid=$uid\"</script>";
      }
    }
    else
    {
      echo "<script>alert('头像上传失败!请重试!')</script>";
        echo "<script>window.location.href=\"pcenter.php?uid=$uid\"</script>";
    }
    mysqli_close($conn);
?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值