Below is code for searching and displaying images based on username:
<?php
$s=0;
if(isset($_POST['submit'])){
$servername = "localhost";
$username = "root";
$password = "123456";
$dbname = "photost";
$conn=mysqli_connect($servername, $username, $password, $dbname);
$user_id=$_POST['user_id'];
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$query="SELECT `id`,`image`, `file_name` FROM `images` WHERE `u_id`='$user_id'";
$result =mysqli_query($conn, $query);
$s=1;
}
?>
<body>
<div style="width:100%;height:10%;">
</div>
<div align=center>
<form action="" method="POST" enctype="multipart/form-data">
<table style="width:40%">
<tr>
<th align="right">User Id:</th>
<th> <input type='text' name='user_id'></th>
<th align="left"> <input type="submit" name="submit" ></th>
</tr>
</table>
</form>
</div>
<div style="width:80%;height:1000px;margin:auto;">
<?php
if($s==1){
if (mysqli_num_rows($result) > 0) {
$c=1;
while($row = mysqli_fetch_assoc($result)) {
echo "<div style='width:24%;float:left;margin-left:2px;margin-top:5px;'>";
echo "<img style='height:250px;width:80%;margin:auto;' src=getImage.php?id='$row[id]' /><br>";
echo $row["id"] .". ". $row["file_name"]."<br></div>";
}
}
}
?>
</div>
</body>
Below code is for fetching image from db based on image id:
<?php
if(isset($_GET['id'])){
$id = $_GET['id'];
$servername = "localhost";
$username = "root";
$password = "123456";
$dbname = "photost";
$conn=mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
header("content-type: image/jpeg");
$query="SELECT `image` FROM `images` WHERE `id`='$id'";
$result =mysqli_query($conn, $query);
$row = mysql_fetch_assoc($result);
echo $row['image'];
}
?>
Tried Many Solution Nothing Worked.I'm able to display one image using header("content-type: image/jpeg") in main page.but while using it in getimage.php only image icon is displayed.as shown below:
Screenshot (Images where userid=1)
Plz Suggest me something.....