Reputation: 21
In my Database, the images(jpeg,bmp format) are stored in bytea datatype, showing up in binary code in the database. Now I want to retrieve the images from the database. But i could not get the image in the web page. When i retrieve using this code given below, it shows the binary code value.(ie combination of numbers,characters,symbols). My code was
$dbconn = pg_connect("host=localhost user=xxxx password=xxxx dbname=xxxx")
or die('Could not connect: ' .pg_last_error());
$rs = pg_query($dbconn, "select scan_image from image where cno='4' and imageno='1'");
$image = pg_escape_bytea(pg_fetch_result($rs, 0));
echo $image;
Am i correct with this code? Please help me to find the solution.
Upvotes: 2
Views: 634
Reputation: 21
U can use Blob to retrieve image from database. And to store image u have convert image to byte using filestream.
This link may help you - http://www.itpian.com/Coding/6298-How-to-retrieve-the-image-to-database-coding.aspx
Upvotes: 1
Reputation: 455322
Before you echo out the image content, you need to set the headers like:
header('Content-type: image/jpeg');
Then you can call your script in an image tag of the page where you want the fetched image to be displayed:
<img src="name_of_your_script.php">
This link will help you: Managing Images With a Web Database Application
Upvotes: 6