帮我看看吧,实在看不出来那错?

amavis 2000-08-29 01:37:00
我仿照一篇文章坐了一个图片上传到SQL Server然后显示的例子
数据库中已经可以看见记录了
可是图片老是显示为一堆乱码,浏览器不能识别,让我下载
是存时的错,还是读时的错?
请赐教!

'***********Saveimage.asp**********************
response.buffer=true
totalsize=request.totalbytes
imagedata=request.binaryread(totalsize)
bncrlf=chrB(13)&chrB(10)
divider=leftB(imagedata,clng(instrB(imagedata,bncrlf))-1)
datastart=instrB(imagedata,bncrlf&bncrlf)+4
dataend=instrB(datastart+1,imagedata,divider)-datastart
mydata=midB(imagedata,datastart,dataend)
%>
<!--#include file="adocon.asp" --> '数据库连接设置
<%set rst=Server.CreateObject("ADODB.Recordset")
rst.open "Select * from images where 1<>1",conn,1,3
rst.addnew
rst("image").appendchunk mydata&chrB(0)
rst.update
rst.close
conn.close
set rst=nothing
set conn=nothing
%>

‘********************Viewimg.asp******************
<!--#include file="adocon.asp" -->
<%
id=Request.QueryString("id")
if id="" then id="1"
id=cint(id)
set rst=Server.CreateObject("ADODB.Recordset")
rst.open "select * from images",conn,1,3
while not rst.EOF
imgid=cint(rst(0))
Response.Write "<a href=""viewimg.asp?id="& imgid & """>" & imgid & "</a>"
rst.movenext
wend
rst.Close
sqlstring="select * from images where id="&id
rst.open sqlstring,conn,1,1
if not rst.EOF then
Response.ContentType = "image/*"
imgsize=rst("image").actualsize
Response.BinaryWrite rst("image").getChunk(imgsize)
else
response.write "图片已经被删除!"
end if
rst.close
conn.close
set rst=nothing
set conn=nothing
%>
...全文
240 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
amavis 2000-08-31
  • 打赏
  • 举报
回复
终于找出来,加了后好了
应该在图片输出前加
response.clear
谢谢大家了!
amavis 2000-08-30
  • 打赏
  • 举报
回复
我用的是IE5.0
应该没什么问题吧
加了这行还是不行呀!
<META content="image/jpg" http-equiv=Content-Type>
jhb 2000-08-30
  • 打赏
  • 举报
回复
试一试别的IE版本,以前我的一个程序在不同的IE上有不同的表现。有一个就和你的一样。
amavis 2000-08-30
  • 打赏
  • 举报
回复
SQLServer中图片字段选择为image
wjl2000 2000-08-30
  • 打赏
  • 举报
回复
把此行:rst("image").appendchunk mydata&chrB(0)

改为:rst("image").appendchunk mydata

试一试!
amavis 2000-08-30
  • 打赏
  • 举报
回复
还是不行!
如果图片不存在可以显示出noexists.gif
但是如果图片存在图片不能显示(红叉)
我试着直接访问outimg.asp?id=1则提示我下载outimg.asp
好像是不认识图片文件格式,我把image/*改为image/jpg还是不行
(数据库中的图片格式是jpg),麻烦各位看看我存图片时有没有问题
saveimg.asp!!
再加50分!!!!!!!!!!
lczddd 2000-08-30
  • 打赏
  • 举报
回复
为何存图片,存路径不行么?然后根据路径在显示图片?!
huntout 2000-08-29
  • 打赏
  • 举报
回复
‘********************Viewimg.asp******************
<!--#include file="adocon.asp" -->
<%
id=Request.QueryString("id")
if id="" then id="1"
id=cint(id)
set rst=Server.CreateObject("ADODB.Recordset")
rst.open "select * from images",conn,1,3
while not rst.EOF
imgid=cint(rst(0))
Response.Write "<a href=""viewimg.asp?id="& imgid & """>" & imgid & "</a>"
rst.movenext
wend
rst.Close
rst.close
conn.close
set rst=nothing
set conn=nothing
response.write "<br><img src='outimg.asp?id=" & id & "'>"
%>


‘********************outimg.asp******************
<!--#include file="adocon.asp" -->
<%
id=Request.QueryString("id")
if id="" then id="1"
id=cint(id)
set rst=Server.CreateObject("ADODB.Recordset")
sqlstring="select * from images where id="&id
rst.open sqlstring,conn,1,1
if not rst.EOF then
Response.ContentType = "image/*"
imgsize=rst("image").actualsize
Response.BinaryWrite rst("image").getChunk(imgsize)
else
response.redirect "noexists.gif"
end if
rst.close
conn.close
set rst=nothing
set conn=nothing
%>

28,390

社区成员

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

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