I am using phpmyadmin for creating my database. I have stored images in a folder called - "images". The path of the image is stored in the database.
I now want to fetch an image corresponding to an id and display it on the screen.
This is how I am storing my image.
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype) {
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
}
if (!empty($_FILES["uploaded_image"]["name"]))
{
$file_name=$_FILES["uploaded_image"]["name"];
$temp_name=$_FILES["uploaded_image"]["tmp_name"];
$imgtype=$_FILES["uploaded_image"]["type"];
$ext= GetImageExtension($imgtype);
$imagename=date("d-m-Y")."-".time().$ext;
$target_path = "images/".$imagename;
if(move_uploaded_file($temp_name, $target_path)) {
$query="insert into users(images_path,submission_date,image_name)values('".$target_path."','".date("Y-m-d")."','$imagename')";
Now, I want to fetch the image and display it on the screen.This is the code I have written -
$connection = mysql_connect("localhost", "root", "");
$db = mysql_select_db("project", $connection);
$query = mysql_query("select * from users where _id= '$r'");
$rows = mysql_num_rows($query);
if ($rows == 1 ) {
$row1=mysql_fetch_assoc($query);
$image=$row1["images_path"];
}
What should I write after this so that the image is displayed?