所以我正在尝试为我的网站创建图片上传,但我希望每个用户都可以上传自己的图片。我有一个工作代码,但我无法弄清楚如何将其设置为每个用户可以上传自己的图片的位置。我知道它与会话开始有关,但我不知道是什么。我自学了自己的代码,所以我仍然无能为力。
<?php session_start();
$_SESSION['username'] = "buttcakes";
?>
<?php
if(isset($_POST['submit'])){
move_uploaded_file($_FILES['file']
['tmp_name'],"picture/".$_FILES['file']['name']);
$con = mysqli_connect (all correct on my end);
$q = mysqli_query($con,"UPDATE user3 SET image = '".$_FILES
['file']['name']."' WHERE username = '".$_SESSION['username']."'");
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="submit">
</form>
<?php
$con = mysqli_connect
("local", "mine", "", "mine");
$q = mysqli_query($con,"SELECT * FROM user3");
while($row = mysqli_fetch_assoc($q)){
echo $row['username'];
if($row['image'] == ""){
echo "<img width='100' height='100'
src='picture/default.jpg' alt='Default Profile Pic'>";
} else {
echo "<img width='100' height='100'
src='picture/".$row['image']."' alt='Profile Pic'>";
}
echo "<br>";
}
?>
</body>
</html>