Showing an image on web browser

Hi,
I’m a newbie here and i’m trying hard to code in php and i’m facing little but crucial problems as well. I have created a database table in mysql in which i have stored an image as blob. Now I want to retreive that image and show it on my web page. For this i guess i’ll have to provide link in src tag of html. Can someone please tell me how to do that?
My blob image is visible when I’m accessing it standalone but not when it is included in the html page’s src tag where i want to show it.
Please help and thanks for your help in advance.

My blob image is visible in stanalone browser so i think there is no problem in accessing the image.

Hi,

Are you storing image_type in database? If not then you have to store that image type in database and also you have to store image height and width.

For getting image from database here is the script. Place this script on root folder of your project.

Image.php

$Imageid = $_GET[‘image_id’];

mysql_select_db($database_testConn, $testConn);

$query = sprintf(“SELECT imagetype, image FROM images
WHERE image_id = $Imageid”);

$getImage = mysql_query($query, $testConn) or
die(mysql_error());

$row = mysql_fetch_assoc($getImage);

$totalRows = mysql_num_rows($getImage);

mysql_free_result($getImage);

header('Content-type: ’ . $row[‘imagetype’]);

echo $row[‘image’];

You have to call this script like this from html page. Here is the example

Image from DB

Sponsor our Newsletter | Privacy Policy | Terms of Service