Jump to content


retrieving images from mysql

  • Please log in to reply
2 replies to this topic

#1 benzeina

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 September 2006 - 06:12 AM

Hi everyone,

I've been trying this for two days. I feel hopeless :(. Basically I managed to load an image to my mysql. the problem is when displaying the image. It returns about 400 lines of  this --->  "x� ��yr��{�ΐN����E<�l>A�fLF������".

here is my image insertion:

if ($_POST['Submit']) {
if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {
mysql_connect("localhost", "username", "password") or die(mysql_error());

$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"), $_FILES['file']['size']));
$query = sprintf("INSERT INTO Cars(Picture, FileType) VALUES ('%s', '%s')", $photo, $_FILES['file']['type']);

Is there something missing. I do have the 'Picture' field of type BLOB !

and i use this to retrieve it:
<img src="<?php echo $result_ar['Picture']; ?>" width="144" height="108" border="0" id="Image1" /></a></a></td>

I would really appreciate your help. Thank you so much in advance.


#2 btherl

  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 19 September 2006 - 07:26 AM

You can't just put an image into the src attribute.  The script that displays the picture needs to do nothing else but display that picture.. then another script needs to call that one.

Script 1:

Get picture from database
header('Content-type: image/gif'); or whatever the image is
print $result_ar['Picture'];

Script 2:
<img src="/script1?img=Image1" width="144" height="108" border="0" id="Image1" />[/url][/url]</td>

Does that makes sense?  The HTML in script 2 says to call script1 to get the image for display.  It can't be done in a single script (not any way I know of)

#3 benzeina

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 September 2006 - 06:07 PM

great i will give this a try. I asked few people about this. There is one way you can do this in one script which is using base64 encoding the displaying it. or something like that. but its not supported by all browsers.  Not trying to be an expert, just wanted to share as you just did. Thank  you :)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users