Print Page | Close Window

Storing images in MySQL

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=12613
Printed Date: 30 March 2026 at 7:50pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Storing images in MySQL
Posted By: webbasterd
Subject: Storing images in MySQL
Date Posted: 19 November 2004 at 5:38pm

Hi,

I have a small question regarding storing images in MySQL. I have a classic ASP based website and a MySQL backboned database. In the MySQL database I made a table TblImages to store some images. In order to show a image on the site I use the ASP file image.asp?ID=2 This is the code I used in the image.asp file:

ID=Request("ID")
adoCon.Open strCon
StrSQL = "SELECT * FROM TblImage where Image_ID =" & ID
AdoRec.Open strSQL, AdoCon
Response.ContentType = "image/gif"
Response.BinaryWrite AdoRec("Image")


I also used some code to prevent the ASP files are cached

Response.Expires = -1
Response.ExpiresAbsolute = Now() - 2
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "No-Store"
Response.Buffer = True

When I use this the image is not stored in the temp. internet files. This is useful for me because nobody can steel copyrighted images.

What I would like to know is if I use this procedure, will there be a preformance loss in viewing the webpage  or is there no diferance when I use <img src="ImageName.gif"> ? (I use the code to prefent caching on all the ASP pages)

Thanks in advance.

Alexander




Replies:
Posted By: dpyers
Date Posted: 19 November 2004 at 7:25pm

Well, you have to open and read the db for each image, but that's offset by the filessytem opening a regular image. I'd call it a wasy unless your connection to the db is really slow.

This method is useful for preventing hotlinks if you check http_referrer in image.asp to ensure that the request is coming from within your site, but it won't prevent the image from being taken.



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

Lead me not into temptation... I know the short cut, follow me.


Posted By: webbasterd
Date Posted: 21 November 2004 at 4:47pm

Thanks for the info! I was testing with the http_referrer to prevent hotlinks but some firewalls block reffers. I found a workarround without checking the reffer. On the page where I call the image.asp I fill a session("FromSite") variable. In the image.asp I check if the variable is filled or not......  This works fine :-)

--
Alexander




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net