Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Quote:
I have seen "how-tos" showing how to store these as blobs then use <img> tags or something to that effect to output them as the original image, but I cant figure out how to make that work with my script. Also, I am not sure how to do this the way you say to do it either. Can you help me out on this?
How can I pull the database info on someone and the images from the outside file...how does it know what images to pull?? that is very confusing to me.
|
You have to create a specific PHP script to display them.
Your problem now is that you need to send an content-type header to the browser to tell it what kind of image you have. jpg, png, or gif.
Now, if you don't already convert them at upload, you can convert them from an unknown type to jpeg at display time with PHP gd functions:
file "image.php":
PHP Code:
<?php require("dbLayer.php"); //connection to the DB $IMG_ID=$_GET['id']; //The image id to fetch
$query=<<<SQL SELECT datas FROM images WHERE id=$IMG_ID SQL; $res=mysql_query($query); while($o=mysql_fetch_object($res)){ //output jpg version of the image header('content-type: image/jpeg'); imagejpeg(imagecreatefromstring($o->datas)); exit() } ?>
Then, you can create img tags like this:
HTML Code:
<img src="image.php?id=12345" alt=""/>
and the image stored into your db will be automatically converted to jpeg and displayed
But I concur what both Insensus and Extbrief have said before me.
Storing images in the DB add overhead to the process.
If you don't need a distributed service (ie: several servers in a cluster working together) then storing the image in a given folder at upload time and storing the file name and/or path would be both simpler and more resource wise.
__________________
Only a biker knows why a dog sticks his head out the window.
|