Forum Moderators: coopster

Message Too Old, No Replies

displaying blob column with php

         

phex

11:31 am on Sep 19, 2008 (gmt 0)

10+ Year Member



i am having trouble displaying images stored as blob in tbl_images. everything exept the image column appears fine. instead of the image i get an allien language like this:

ɮ NP^jV}U^%nye>9oJ@'t8ͩuY'OGה*Ԫm tU0AӻZ]_; O @,w? ǽ;5lew}R/cם Ou$XVv)uH_+ȊL0k

what should i do?

the structure of the image is like this:

id= int
image= blob
your_name= varchar(255)
email= varchar(255)
description= varchar(255)
time= timestamp(14)

the php code to display all the above info is:

<?php
$conn= mysql_connect("localhost","*****","*****") or die ("Error: conn");
$rs= mysql_select_db("test", $conn) or die ("error: db");

$sql= "select * from tbl_images";
$rs= mysql_query($sql, $conn);

while( $row = mysql_fetch_array($rs))
{

echo("PHOTO POSTED AT-". $row["time"]."<br>");
echo("PHOTO TAKEN BY-". $row["taken_by"]."<br>");
echo("EMAIL-". $row["email"]."<br>" );
echo("DESCRIPTION-". $row["description"]."<br>");
echo ("<hr>". $row["image"] ."<br><hr><hr><hr>");

}

?>

phranque

12:59 am on Sep 20, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], phex!

the correct way to display an image using the http protocol is either as an image tag in an html document or as a media file with the proper content type header.
in the html case, the image tag must refer to a url which serves a media file with the proper content type header.

the way you have it now you are trying to print the blob as text in an html document.