我已经有一个适当的图像上传系统。它上传&存储图像的文件夹/uploads/
的,现在我需要跟踪谁上传个人资料图片,我想我的用户个人资料页上显示图像。允许用户上传PHP中的配置文件图像
这是我的upload.php的:
<?php
include('db.php');
// Check if user is logged in using the session variable
if ($_SESSION['logged_in'] != 1) {
$_SESSION['message'] = "You must log in before viewing your profile page!";
header("location: error.php");
}
if (isset($_POST['submit'])) {
$file = $_FILES['file'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fileType = $file['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png', 'pdf');
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 1000000) {
$fileNameNew = uniqid('', true).".".$fileActualExt;
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
header("Location: user.php");
} else {
echo "Your file is too big!";
}
} else {
echo "There was an error uploading your file!";
}
} else {
echo "You cannot upload files of this type!";
}
}
,这是HTML:
<form action="upload.php" method="POST" enctype="multipart/form-data" >
<div class="specialcontainer">
<input type="file" name="file" id="file" class="inputfile">
</div>
<div class="inner"></div>
<button type="submit" name="submit" class="uploadbuttonstyle">Upload</button>
</form>
</div>
我为此具有两个表,一个处理的用户名,FNAME, lname,电子邮件,密码,用户描述等。我希望第二个显示他们的个人资料图片的状态,即如果他们上传了图片,状态将为1,如果他们没有,那么状态将为0。如果状态为0,将显示目录/uploads/profiledefault.jpg
的图像,这是新用户的默认配置文件映像。谈到PHP时,我仍然是一名初学者。希望有人能在这里向我展示。
我猜我将不得不使用UPDATE查询来更新profile_image列,并且WHERE子句将为每个用户(例如他/她的电子邮件)包含一个唯一值? –
绝对正确! – Sehdev