php - 从用户名文件夹中获取图像
问题描述
您好我正在开发一个网站,在注册表单上,将用户名密码和图像上传到数据库中,为每个用户创建一个专用文件夹。现在我要做的是在用户登录时获取图像,显然应该显示的图像将是用户在注册时上传的图像。是否可以在没有 id 但使用用户名文件夹的情况下这样做?这就是我上传图像的方式。
$username = $_POST ['username'];
$password = $_POST ['password'];
$email = $_POST ['email'];
$image = $_FILES['image']['name'];
$image_tmp = $_FILES['image']['tmp_name'];
$s = " select * from usertable where username = '$username'";
$result = mysqli_query($con, $s);
$num = mysqli_num_rows($result);
if($num == 1){
echo "Username Already Taken";
}else{
mkdir("Images/$username", 0777, true);
move_uploaded_file($image_tmp,"Images/$username/$image");
$reg= "insert into usertable(username, password, email,imagename) values ('$username', '$password', '$email','$image')";
mysqli_query($con, $reg);
echo "registration successfull";
}
登录表单
$username = $_POST ['username'];
$password = $_POST ['password'];
$s = " select * from usertable where username = '$username' && password = '$password'";
$dirname = "images/$username";
$images = glob($dirname."*.png");
$result = mysqli_query($con, $s);
$num = mysqli_num_rows($result);
if($num == 1){
$_SESSION['images']= $images;
$_SESSION['username']= $username;
header('location:home.php');
}else{
header('location:index.php');
}
主页
<title>Welcome</title>
</head>
<body >
<a href ="logout.php"> Log Out </a>
<img src="<?php echo $_SESSION['images']; ?>"/>
<h1>Welcome <?php echo $_SESSION['username']; ?></h1>
解决方案
推荐阅读
- r - 在 edgarWebR 1.1.0 中使用地图功能时出错
- c++ - 这是我在 C++ 中的链表的代码。删除最后一个节点后,deleteAtEnd 方法出现问题,它显示一些垃圾值。我找不到错误
- amazon-web-services - 使用 k8s SDK 应用 yaml 文件
- c# - Blazor - 如何在退出页面时停止计时器
- docker - 尝试在本地 PC 中启用 RBAC 时 Minikube 运行异常
- c# - 如何使用 C# 从 url 获取/读取文本文件?
- java - 使用 REST API 上传到 Azure Blob Store 时,Zip 档案损坏
- git - 如何删除特定分支的第一次提交?
- xquery - Xquery 多个重复节点
- firebase - Flutter:GraphQLError:uuid 类型的输入语法无效:“”