How to display only the images loaded by a specific user?
I did get my program to work, I able to upload a image save as a file in the database and display it. There's just one thing, when I go to select a image that has been loaded by a user it shows me every image that was loaded, how do I just only show the images loaded by the specific user signed in to select ?
Here's the code for the loading the file:
<?php require 'Connections/Connections.php'; ?>
<?php
if(isset($_FILES['UploadFileField'])) {
$UploadName = $_FILES['UploadFileField']['name'];
$UploadName = mt_rand(100000, 999999).$UploadName;
$UploadTmp = $_FILES['UploadFileField']['tmp_name'];
$UploadType = $_FILES['UploadFileField']['type'];
$FileSize = $_FILES['UploadFileField']['size'];
$UploadName = preg_replace("#[^a-z0-9.]#i", "", $UploadName);
if(($FileSize > 1000000)) {
die("Error - File Size");
}
if(!$UploadTmp){
die("No File Seleced, Try Uploading again");
}else{
move_uploaded_file($UploadTmp, "Upload/$UploadName");
}
}
?>
<!doctype html>
<html>
<head>
<link href="CSS/Master.css" rel="stylesheet" type="text/css" />
<link href="CSS/Menu.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8"
<title>File Upload</title>
</head>
<body>
<div class="Container">
<div class="Header"></div>
<div class="Menu">
<div id="Menu">
<nav>
<ul class="cssmenu">
<li><a href="Account.php">Account</a></li>
<li><a href="UpdateAccount.php">Update Account</a></li>
<li><a href="NewRequest.php">New Request</a></li>
<li><a href="ReviewRequest.php">Review Request</a></li>
<li><a href="LogOut.php">Log Out</a></li>
</ul>
</nav>
</div>
</div>
<div class="LeftBody"></div>
<div class="RightBody">
<p class="p"> Please include all files you would like to be uploaded below.</p>
<form action="FileUpload.php" method="post" enctype="multipart/form-data" name="FileUploadForm" id="FileUploadForm">
<label for="UploadFileField"></label>
<input type="file" name="UploadFileField" id="UploadFileField">
<input type="submit" name="UploadButton" id="UploadButton" value="Upload">
<p class="p"> When Finish Return to New Request to Include the Files</p>
</form>
</div>
<div class="Footer"></div>
</div>
</body>
</html>
Here's the code for selecting and storing the image:
<?php require 'Connections/Connections.php'; ?>
<?php
if(isset($_POST['NewRequest'])) {
session_start();
$FName = $_POST['First_Name'];
$Location = $_POST['Location'];
$Description = $_POST['Description'];
$image_name = $_POST['image_name'];
if($image_name == "") {
$no_image_selected = true;
}
else {
$image_selected = true;
}
$sql = $con->query("INSERT INTO newrequest (Fname, Location, Description, image_name)Values('{$FName}','{$Location}','{$Description}','{$image_name}')");
header('Location: Account.php');
}
?>
<!doctype html>
<!doctype html>
<html>
<head>
<link href="CSS/Master.css" rel="stylesheet" type="text/css" />
<link href="CSS/Menu.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8"
<title>NewRequest</title>
</head>
<body>
<div class="Container">
<div class="Header"></div>
<div class="Menu">
<div id="Menu">
<nav>
<ul class="cssmenu">
<li><a href="Account.php">Account</a></li>
<li><a href="UpdateAccount.php">Update Account</a></li>
<li><a href="NewRequest.php">New Request</a></li>
<li><a href="ReviewRequest.php">Review Request</a></li>
<li><a href="LogOut.php">Log Out</a></li>
</ul>
</nav>
</div>
</div>
<div class="LeftBody"></div>
<div class="RightBody">
<form "insert_info" action="" method="post" name="NewRequest" id="NewRequest">
<div class="FormElement">
<label for=""></label>
<input name="First_Name" type="text" required class="TField" id="First_Name" placeholder="First Name" >
</div>
<div class="FormElement">
<label for=""></label>
<input name="Location" type="text" required class="TField" id="Location" placeholder="Location" >
</div>
<div class="FormElement">
<label for="Description"></label>
<textarea name="Description" required class="TField" id="Description" placeholder="Description" ></textarea>
</div>
<div class="FormElement">
</div>
<a class = afield href="FileUpload.php">File Upload</a>
<select name="image_name" id="image_name">
<option value="">Select Image</option>
<?php
$a = array();
$dir = 'Upload';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if (preg_match("/\.png$/", $file)) $a[] = $file;
elseif (preg_match("/\.jpg$/", $file)) $a[] = $file;
elseif (preg_match("/\.jpeg$/", $file)) $a[] = $file;
elseif (preg_match("/\.gif$/", $file)) $a[] = $file;
}
closedir($handle);
}
natsort($a);
foreach ($a as $i) {
echo "<option value=".$i.">".$i."</option>";
}
?>
</select>
<input name="NewRequest" type="submit" class="button" id="Send" value="Send">
</form>
<?php
if(isset($image_selected)) {
echo "<p>Image name successfully inserted into database</p>";
}
elseif(isset($no_image_selected)) {
echo "<p>Please select an image name</p>";
}
?>
</div>
<div class="Footer"></div>
</div>
</body>
</html>
When I go to select image, I just want to be able to view the images uploaded by the users sign in, not by every user that has uploaded a image.Is there a way to do this any suggestions will be helpful?
