在用asp编程中,很多时侯要用到图象。对于单纯从数据库中处理一个图象,方法大家讲了很多,也不难,可以看下面的代码:这里假设你有个数据库名字叫:pubs,在数据库中有一个叫:pub_info的表,在表中有一个logo的blob列。我们查出pub_id=0736的人的相片。
file: showimg.asp
***************************************
<%@ language="vbscript" %>
<%
clear out the existing http header information
response.expires = 0
response.buffer = true
response.clear
change the http header to reflect that an image is being passed.
response.contenttype = "image/gif"
set cn = server.createobject("adodb.connection")
the following open line assumes you have set up a system datasource
by the name of mydsn.
cn.open "dsn=mydsn;uid=sa;pwd=;database=pubs"
set rs = cn.execute("select logo from pub_info where pub_id=0736")
response.binarywrite rs("logo")
response.end
%>
*****************************************
执行这个asp文件就可以看到你存在数据库中的图象了。
但如果是同时处理文字和图象就会有些困难了:-(
比如:一个企业的人员管理,后台数据库可以用sybase或sql server等。(我在这用sql server)当你在企业内部需要用到browse/server方式,即用浏览器查看员工的个人信息时,就即要处理文字信息同时还要用到关于图象的技巧。
问题在于你显示文字信息时html的head中的content=“text/html”,而显示图象则必须是content=“image/gif”或者是content=”image/jpeg“。因此你是无法只用一个asp文件就把文字信息和图象都处理完的,解决的办法是:用一个单独的asp文件处理图象,然后在处理文字信息的asp文件中调用这个asp文件。
在这给大家介绍一个我的解决方法,希望大家一起讨论:
环境:winnt4.0 sql server iis3.0
数据库名:rsda
表名:rsda_table
目的:从rsda_table中查出id=00001的人员的信息,包括姓名,年龄和照片
第一步:创建一个查询表单rsda.htm:
**********************************
<html>
<head>
</head>
<body>
<form method ost" action="search.asp">
<p>请输入编号:<input type="text" name="t1" size="20"><input
type="submit" value="提交" name="b1"><input type="reset" value="复原" name="b2"></p>
</form>
</body>
</html>
***********************************
第二步:建立search.asp
***********************************
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<title>查询结果</title>
</head>
<body bgcolor=azure>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器