How to display image on web page from ADODB.stream object

[亡魂溺海] 提交于 2019-12-24 10:38:29

问题


I have a classic ASP question. I need to show images on my webpage. But because of the security reasons, I cannot simply put all of my images in the images folder in my website folder and I need to put them outside of my website folder. For example, my website folder is located at: C:\Inetpub\wwwroot\mysite\ But I need to put images (which I want to show on my web pages) at: C:\images\

I am trying to use ADODB.stream object to pull the images using ASP vb codes as shown below:

<%
Response.ContentType = "image/png"
Set adoStream = Server.CreateObject("ADODB.Stream") 
adoStream.Open
adoStream.Type = 1
FPath = "C:\images\1.png"
adoStream.LoadFromFile FPath

Response.BinaryWrite adoStream.Read 

adoStream.Close
Set adoStream = Nothing 
Response.End
%> 

When I launch this webpage in internet explorer, the page shows a File Download window/message for downloading the image file "1.png" rather than displaying the image on the web page. How can I fix the code to show the image on the web page rather than downloading the image file?


回答1:


That code generates an image as the return type, so there is no HTML to display the image in, if you call this code directly say it's called image.asp then you would do something like this in another page that displays HTML.

<img src="image.asp" />

This will call your code and output the raw image binary as this is what <img> expects.

If you want to produce multiple images from the file system or database pass a querystring parameter such as ?id=yourimage and change the code to select different images.



来源:https://stackoverflow.com/questions/28822488/how-to-display-image-on-web-page-from-adodb-stream-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!