Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Viewing an Image from MySQL

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
I read everything here about it (some of this code might look familiar) but nothing seems suitable to my needs so I hope there is a way. I need to loop through the images table, pulling out one or two for presentation on various existing pages using the ID field, which is also being taken care of already in the Select statement for the loop, but all I can get is the source of the image, not the image itself. Here is what I have - there is already a database connection and this is already inside a loop, and the variables for $image are already declared:

[tt]$mime = array("JFIF" => "jpeg",
"GIF89" => "gif");

if ($image != '') {
$content = base64_decode($image);

while(list($key,$val) = each($mime)) {
if(ereg($key,$content)) {
$mime_type = $val;
}
}
$image = &quot;<img src=\&quot;&quot; . $content . &quot;.&quot; . $mime_type . &quot;\&quot;>&quot;;
}[/tt]

I think what I need to do is in the loop, to actually create a physical temp copy of the image somewhere in a temp folder and then after it's presented, to delete it again but I am not sure how to do that. Any ideas? Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Because I added the files to the table enmasse, I had no way to do that. I was hoping that the little $mime code at the top of my snippet would do it but as I didn't write it myself, I am unsure of how (or if) it works. It came from another tek-tips posting by someone else. Anyway, thanks for the help and I will try some of these things tonight. Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Since I have only a few images in the test table right now (I already deleted all the extra entries since they were making the testing too slow), if someone can help me come up with come code for selecting more than one image at a time that could insert them into the table, I would like to do so while at the same time populating a field with the existing file name and the height/width too. I inserted them originally using MySQL-Front which inserts only the image itself. Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top