Jump to content


Photo

retrieve images from mysql


  • Please log in to reply
1 reply to this topic

#1 benzeina

benzeina
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 September 2006 - 02:02 PM

Hi everyone,

I've been trying this for two days. I feel hopeless Sad. 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']) {
//print_r($_FILES);
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("Vehicles");

$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" />[/url][/url]</td>

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

Ben

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 September 2006 - 09:54 AM

Well, what you've stored in the DB is the actual binary content of your file -- you'll need to return this information, with appropriate headers, if you want to serve it on-the-fly.  This will necessitate another script that streams this data appropriately, which you will then call with via src attribute on your IMG tag (and simply pass it a UID or other unique value to lookup).  I've seen many examples of such a code snippet posted in this forum recently as well.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users