如何从ADODB.stream对象在网页上显示图像 [英] How to display image on web page from ADODB.stream object

查看:141
本文介绍了如何从ADODB.stream对象在网页上显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个经典的ASP问题. 我需要在网页上显示图像. 但是出于安全原因,我不能简单地将所有图像放在网站文件夹的images文件夹中,而需要将它们放在网站文件夹之外. 例如,我的网站文件夹位于: C:\ Inetpub \ wwwroot \ mysite \ 但是我需要将图像(要显示在我的网页上)放在: C:\ images \

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\

我正在尝试使用ADODB.stream对象通过如下所示的ASP vb代码提取图像:

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
%> 

当我在Internet Explorer中启动此网页时,该页面显示文件下载窗口/消息,用于下载图像文件"1.png",而不是在网页上显示图像. 如何修复代码以在网页上显示图片,而不是下载图片文件?

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?

推荐答案

该代码生成图像作为返回类型,因此没有HTML显示图像,如果直接调用此代码,则称其为image.asp那么您将在另一个显示HTML的页面中执行类似的操作.

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" />

这将调用您的代码并输出原始图像二进制文件,这正是<img>所期望的.

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

如果要从文件系统或数据库中生成多个图像,请传递查询字符串参数(例如?id=yourimage)并更改代码以选择其他图像.

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.

这篇关于如何从ADODB.stream对象在网页上显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆