Forum Moderators: coopster

Message Too Old, No Replies

Image from DB not showing up

         

neophyte

1:09 pm on Sep 11, 2004 (gmt 0)

10+ Year Member



I'm successfully getting a row of information from a db (three columns in the row: two varchar and one BLOB)but when I display it, the two varchar rows come out fine, but the BLOB (a small .jpg image) is represented by an "x" image icon - you know, the kind you get when the browser can't find the image.

Probably just my .php syntax that's causing the problem, and here it is:

<td><img src=\"$intro[4]\"></td>

What syntax do I need to use to get the image to show?

-------------------------------

Also, does the database "need" to be open to display images? I'm using a function to grab the rows from the db. After the function grabs the rows, it closes the db, then returns the "result" to another function that displays everything. So I'm wondering, for image display, does the db need to be open?

As mentioned, everything else comes out just fine.

All assitance, as always, greatly appreciated.

Neophyte

mincklerstraat

2:45 pm on Sep 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One of the problems with using BLOBS is that you need to have a separate request for each image - you can't just request one php file, and have that also generate your images. Look at the source code that's produced by your script, and you'll see <img src="LOTSOFBINARYéç!(è"'">.

To use the BLOB method, you need something like <img src="image.php?dbreq=IDNO"> in the main page file. Then you have a php script called image.php that takes the GET variable dbreq, uses it as an id to search for your BLOB, and outputs it after having output the appropriate headers, such as:
header('Content-type: image/png'); (if it's a png, for example).
So it means a separate db connection (which is big on overhead time) and a separate db request is necessary for each image grabbed.
Nb, you'll also want to put out some kind of cache headers, since images should usually be cached by ip's, and usually ip's won't cache php files since they don't have any caching information by default. Some ip's also won't cache anything with a parameter in the url, so many ip's won't cache your images at all, have fun paying for your bandwidth and hope you've got a heavy-duty db installation!

Maybe in some future version of http protocol there will be a way of embedding inline image binary information into the html document, like can be done in e-mails, but you'll probably have to wait.

Best practices tend to be simply storing the image in your filesystem, and either having it named according to an id field of your db, or storing the name in the db.

neophyte

2:26 am on Sep 12, 2004 (gmt 0)

10+ Year Member



Yikes. That's all very scary and "over my head" kind of stuff. Maybe keeping images in a databse isn't a good idea after all?

I'll be scouring the net for tutorials on how to do this. Thanks for your help ... anyone else have any input on this issue or additional best practices in regards to same, I'd love to hear it because I'm kind of at a brick wall at this point with this one issue and how to solve it.

Neophyte

neophyte

6:03 am on Sep 13, 2004 (gmt 0)

10+ Year Member



mincklerstraat

After a lot of fretting (and cigarettes) I finally just tried inputing the image name into the table field (along with the directory path) and now the image displays perfectly everytime.

Thanks for your help.

Neophyte

mincklerstraat

7:14 am on Sep 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Great to hear it. Always a rush when something new works!