Page 1 of 2

BLOB image appearing as characters

Posted: Thu Apr 17, 2008 12:57 pm
by khushbush
I've been trying to get images to show up on my search page, but it keeps showing up as random characters, e.g. ‰usªêÂÚØæÊÙ€Û£

My images are stored as BLOBs in the database...I've already tried storing and displaying images as file pathnames, but to no avail.
I've tried most methods by Googling my problem, but it still doesn't seem to work. I've saved the image display method in one file, and then called that image in another php file and displayed it using the <img src> tag...and yet it still shows up funny characters.

I am going to post the code up for both php files.

This is code from showimage.php:

Code: Select all

 
<?php
  header("Content-Type: image/jpeg");
 
  mysql_connect(" ", " ", " ") or die(mysql_error());
 
  mysql_select_db("property") or die(mysql_error()); 
 
 
 
 // Put the value in a separate variable
  $propID = ($_GET['id']); 
  $query = "select propertyImage1, propertyImage2, propertyImage3 from property where propertyID = $propID";
  $result = mysql_query($query) or die(mysql_error());
 
 
if($row = mysql_fetch_array($result)){
  $imageData1 = $row['propertyImage1'];
}
header('Content-Type: image/jpeg');
echo $imageData1;
?>
 
And here is the code from searchprocess.php where the image is to be displayed:

Code: Select all

 
<HTML>
<BODY>
<table ALIGN = "LEFT">
<font face="Arial" color="#0B3A62">
 
<?//display results?>
 
Property area: <? echo $row[0]; ?> , 
Starting bid: £<? echo $row[1]; ?> , 
<? echo $row[2]; ?> ,
<? echo $row[3]; ?> bedroomed,
<? echo $row[4];?>
<? echo $row[5];?>
   <br>
   <br>
   <tr><tr><td><?echo "<img src =\"showimage.php?id=$row[propertyID]\">";?></td></tr></tr>
   </br></br>
 
Any thoughts/ideas?

Re: BLOB image appearing as characters

Posted: Thu Apr 17, 2008 1:47 pm
by onion2k
According to the code you posted for showimage.php the opening PHP tag (<?php) is on line 2. That means you're outputting a carriage return first. That will be enough to break the image.

You're also outputting the content type header twice but that shouldn't be a problem.

Re: BLOB image appearing as characters

Posted: Thu Apr 17, 2008 2:21 pm
by khushbush
No, that's just the way I posted the code...apologies for that. :oops:
There are no extra lines or spaces above the php tag.

The double header doesn't make a difference, as I am able to display images in another file. Can't seem to do the same with this one... :?

Re: BLOB image appearing as characters

Posted: Fri Apr 18, 2008 10:29 am
by pickle
My guess would be that you've got a header conflict. Use FF & download an extension that captures HTTP headers. That might give you an idea.

Re: BLOB image appearing as characters

Posted: Fri Apr 18, 2008 11:55 am
by khushbush
Erm...FF? :oops: Could you please elaborate?

Re: BLOB image appearing as characters

Posted: Fri Apr 18, 2008 12:03 pm
by pickle
Sorry - Firefox.

Re: BLOB image appearing as characters

Posted: Fri Apr 18, 2008 12:11 pm
by khushbush
I already use Firefox...in fact, I practically swear by it! Ok...I'm going off topic...erm...should I Google a HTTP header capture thingy? I guess what I mean to ask is...where would be the best place to download an extension that captures HTTP headers? PHP.net?

Re: BLOB image appearing as characters

Posted: Fri Apr 18, 2008 12:16 pm
by khushbush
Ok, silly me...did you mean something like this?

https://addons.mozilla.org/en-US/firefox/addon/3829

Re: BLOB image appearing as characters

Posted: Fri Apr 18, 2008 12:24 pm
by pickle
Ya -something like that.

Re: BLOB image appearing as characters

Posted: Fri Apr 18, 2008 12:28 pm
by khushbush
I'm unsure how to use it. What am I supposed to be looking for?

Re: BLOB image appearing as characters

Posted: Fri Apr 18, 2008 12:42 pm
by pickle
Look through the header logs for the Content-Type header you sent. I'm guessing there is a Content-Type header being sent before the ones you intend, that change the type from image/jpeg, to text or something else.

Re: BLOB image appearing as characters

Posted: Fri Apr 18, 2008 12:53 pm
by khushbush
Well...it says that the content-type header is set to text/html on the page where I want images to show up...but showimage.php has a content-type header set to image/jpeg...I also think that the problem may lie in the fact that showimage.php is not accessing the image corresponding to the id specified. Could that be a possible cause for the image breaking up?

Re: BLOB image appearing as characters

Posted: Fri Apr 18, 2008 1:36 pm
by pickle
If showimage.php is showing a file that isn't a JPEG image, that's a possibility. It might also be a possibility that the image data was truncated in the database, so you're not getting a complete image.

Remove the first header() so you just set 1. Then echo your query to see if its what you expect.

Also, you don't need parentheses around $_GET['id'] when setting $propID. You also don't need to be retrieving, the propertyImage2 or propertyImage3 fields in your query.

Re: BLOB image appearing as characters

Posted: Fri Apr 18, 2008 4:30 pm
by khushbush
Ok, so I've decided to include showimage.php in searchprocess.php...and the image shows up. Unfortunately, I can't get the desired data to show up from the database...so what can I do to get both the picture and data to show up together?

Re: BLOB image appearing as characters

Posted: Fri Apr 18, 2008 4:34 pm
by pickle
That's a different question than you originally asked correct? Best to open a new thread for that as it will likely have different problems.