怎么正确显示数据库里面的图片?

phoenixv 2002-07-22 07:32:21
我用下面的代码显示数据库里面的图片,但是说什么也不成功,什么也显示不出来。请问哪里错了?




<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body>
<%set myconn=server.createobject("adodb.connection")
sConnection ="dsn=vodCust;uid=sa;pwd=uiojkl;"
myconn.Open(sConnection)


set rec=server.createobject("ADODB.recordset")
strsql="select pic from pic where id=2"
rec.open strsql,myconn,1,1
Response.ContentType = "image/*" %>
<%Response.BinaryWrite rec("pic").getChunk(7500000)%>
<%
rec.close
set rec=nothing
set myconn=nothing
%>

</body>
</html>
...全文
507 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
phoenixv 2002-07-23
  • 打赏
  • 举报
回复
已经解决了,呵呵。。。。谢谢。
ChinaOk 2002-07-22
  • 打赏
  • 举报
回复
http://www.ChinaOK.net/Examples/
yonghengdizhen 2002-07-22
  • 打赏
  • 举报
回复

photoshow.asp
<%
if Request.QueryString("ProductID")="" then
Response.End
end if
%>
<!--#INCLUDE VIRTUAL="/PUBLIC/CONN_OPEN.INC" -->
<%
objRS.Open "SELECT ProductPhoto FROM Product WHERE ProductPhoto<>NULL AND ProductID=" & Request("ProductID"),objDC
if not objRS.EOF then
Response.BinaryWrite objRS("ProductPhoto")
end if
objRS.Close
%>
<!--#INCLUDE VIRTUAL="/PUBLIC/CONN_CLOSE.INC" -->



<img src="/product/photoshow.asp?ProductID=<%=objRS("ProductID")%>" border="0" align="left" vspace="20" hspace="20">
OneGip 2002-07-22
  • 打赏
  • 举报
回复
正确答案:
在Response.BinaryWrite 之前不能有任何html代码,因为例如<html>,实际上等于response.write "<html>"
所以不要写任何html代码,另外,Response.BinaryWrite rec("pic").getChunk(7500000) 这一句可以写成Response.BinaryWrite rec("pic")

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧