| 4GuysFromRolla.com : ASP FAQS : Databases, General | ||||
|
| ||||
| Question: | How can I display images that reside in my database through an ASP page? | |||
|
| ||||
| Answer: | This is a fairly commonly asked question on ASPMessageboard.com. Essentially, you can have images stored in a database in one of two formats: as a text field specifying a URL from where the image can be found; or as a binary field stored within the database. There are times when each approach makes sense. Since we are dealing with the Web, oftentimes it makes more sense to use the former approach, to simply store the URLs to the images as opposed to actually storing the binary contents of the image in the database. Such practices will keep your overall database size small and make displaying images a breeze (just need a simple IMG tag whose SRC attribute uses the database value). The disadvantage with this approach is that is decouples the images from the database. This could be a problem if your database is used on multiple servers scattered throughout the country or world, and the images are on a computer that is, perhaps, only reachable through a certain location, perhaps an intranet of some kind.The other option is to store the image contents into the database as a binary field. As I summarized before, this oftentimes greatly increases the overall size of your database, but is nice because all of the data for your database exists in one location, as opposed to having the images residing separately. So how does one display an image from a database via an ASP page? Using the first technique, assume that your table had a column called ImageUrl, that contained a fully qualified URL to the image file, such as: http://www.yourserver.com/images/hat.gif, or whatever. Then, to display the image via an ASP page, you'd simply need to display an IMG tag like so:
This simply outputs an
That's all there is to it! Realize that you cannot display both binary information and textual information from this ASP page, you can only send the image down the wire. If you want to include this on an ASP page with textual information, you will need to reference the ASP page that displays the image via an
For more information on both of these processes, be sure to read: Displaying Images that Reside in a Database | |||
|
FAQ posted by Scott Mitchell at 11/12/2001 12:49:12 PM to the Databases, General category. This FAQ has been viewed 110,298 times. | ||||
Copyright 2010 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers