再议一个关于图片显示的怪问题
图片存到数据库中没有问题,单独显示一张也没有问题,但如果在一页中列出2张一上图片,结果 所有列出的图片都显示同一张,但每一张图片在数据库中的photoid却不同,说明提取图片没有错误。
我用的是 LyfUpload.dll组件(1.2版本)
----
'show.asp
<%
Function SetForDisplay(field, contentType)
contentType = contentType
nFieldSize = field.ActualSize
bytes = field.GetChunk(nFieldSize)
Session("Bytes") = bytes
Session("Type") = contentType
End Function
%>
<%
rs1.open .........,cn,1,1
for i=1 to 10
photoid=trim(rs1("photoid"))
response.write photoid '10次显示的 photoid却不同 (表明没有取错图片)
set rs=createobject("adodb.recordset")
rs.open "select * from photo where photoid='"&photoid&"'",cn,1,1
SetForDisplay RS("photo"), "image/gif" '"image/gif" 为MIME类型
rs.close
set rs=nothing%>
<img src="theImg.asp" width="100" height="100">
<%rs1.movenext
next%>
-------
'theImg.asp
<%
' theImg.asp proxy page
response.Expires = 0
response.Buffer = True
response.Clear
response.contentType = Session("Type")
response.BinaryWrite Session("Bytes")
Session("Type") ="0"
Session("Bytes")="0"
response.End
%>
我怀疑是session没有释放干净,或者内存中 有类似的 stream 存在,我应该怎么解决?
问题点数:100、回复次数:14Top
1 楼cmsoft(韦小宝是我的老乡)(草根在路上)回复于 2002-08-24 16:21:01 得分 5
Session("Type") ="0"
Session("Bytes")="0"
这个不叫session清空吧@_@
session.AbandonTop
2 楼redfox33(豆子)回复于 2002-08-24 16:31:38 得分 0
我知道,但我不能用session.Abandon,因为每个页面都要用保存的session("count"),session("password")来进行验证,如果用session.Abandon,那就全被清空了!!我该怎么解决这个问题???很急很急!!!!Top
3 楼qiushuiwuhen(秋水无恨)回复于 2002-08-24 16:37:31 得分 0
先执行
<%
rs1.open .........,cn,1,1
for i=1 to 10
photoid=trim(rs1("photoid"))
response.write photoid '10次显示的 photoid却不同 (表明没有取错图片)
set rs=createobject("adodb.recordset")
rs.open "select * from photo where photoid='"&photoid&"'",cn,1,1
SetForDisplay RS("photo"), "image/gif" '"image/gif" 为MIME类型
rs.close
set rs=nothing%>
<img src="theImg.asp" width="100" height="100">
<%rs1.movenext
next%>
服务段重复设置session,但这时theImg.asp并没有调用
所以和session无关,程序问题,
解决方法:不用session
将读取数据库并显示图片那部分代码搁到theImg.asp中
循环for中只有 <img src="theImg.asp?id=<%=photoid%>"Top
4 楼fbj007(千里独行)回复于 2002-08-24 16:43:44 得分 0
cmsoft(韦小宝是我的老乡) 说的没错:)
如你要用到session,这样试试
Session("Type") =""
Session("Bytes")=""Top
5 楼redfox33(豆子)回复于 2002-08-24 17:01:27 得分 0
<img src="theImg.asp?id=<%=photoid%>"
-----
<%
'theimg.asp---
Function SetForDisplay(field, contentType)
contentType = contentType
nFieldSize = field.ActualSize
bytes = field.GetChunk(nFieldSize)
Session("Bytes") = bytes
Session("Type") = contentType
End Function
%>
<%
' theImg.asp proxy page
response.Expires = 0
photoid=request("photoid")
set rs=createobject("adodb.recordset")
rs.open "select * from photo where photoid='"&photoid&"'",cn,1,1
SetForDisplay RS("photo"), "image/gif"
rs.close
set rs=nothing
response.Clear
response.contentType = Session("Type")
'Response.Write(Session("ImageBytes"))
response.BinaryWrite Session("Bytes")
Session("Type") =""
Session("Bytes")=""
response.End
%>
按照 qiushuiwuhen(秋水无恨) 说得改完后还是不行
Top
6 楼redfox33(豆子)回复于 2002-08-24 17:07:21 得分 0
'photo.asp
for i=1 to 10
<img src="theImg.asp?id=<%=photoid%>"
next
-----
'theimg.asp
Function SetForDisplay(field, contentType)
contentType = contentType
nFieldSize = field.ActualSize
bytes = field.GetChunk(nFieldSize)
Session("Bytes") = bytes
Session("Type") = contentType
End Function
response.Expires = 0
response.Buffer = True
photoid=request("photoid")
set rs=createobject("adodb.recordset")
rs.open "select * from photo where photoid='"&photoid&"'",cn,1,1
SetForDisplay RS("photo"), "image/gif"
set rs=nothing
response.Clear
response.contentType = Session("Type")
response.BinaryWrite Session("Bytes")
Session("Type") =""
Session("Bytes")=""
response.End
这样还是不行!!我急疯了
Top
7 楼redfox33(豆子)回复于 2002-08-24 17:08:36 得分 0
更正 上面那行应该是 SetForDisplay photoid,"image/gif"
我刚才写错了Top
8 楼qiushuiwuhen(秋水无恨)回复于 2002-08-24 17:11:53 得分 0
說了不用session了
去掉set rs=nothing 後面的代碼
<%
'theimg.asp---
Function SetForDisplay(field, contentType)
contentType = contentType
nFieldSize = field.ActualSize
response.contentType = contentType
response.BinaryWrite field.GetChunk(nFieldSize)
End Function
%>
Top
9 楼redfox33(豆子)回复于 2002-08-24 17:32:50 得分 0
我找你说的做了,还是不好用啊,怎么班阿Top
10 楼redfox33(豆子)回复于 2002-08-24 17:41:24 得分 0
'theimg.asp---
response.Expires = 0
response.Buffer = True
photoid=request("photoid")
set rs=createobject("adodb.recordset")
rs.open "select * from photo where photoid='"&photoid&"'",cn,1,1
contentType = "image/gif"
nFieldSize = RS("photo").ActualSize
bytes = RS("photo").GetChunk(nFieldSize)
response.contentType = contentType
response.BinaryWrite RS("photo").GetChunk(nFieldSize)
rs.close
set rs=nothin
我都改成这样了也不好用啊,我想知道你以前也遇到过这种情况吗?Top
11 楼qiushuiwuhen(秋水无恨)回复于 2002-08-24 18:02:14 得分 95
很多错误,如cn没设
以及set rs=nothing
下面在本机通过了
<%
response.Expires = 0
response.Buffer = True
photoid=request("photoid")
set conn=server.createobject("adodb.connection")
conn.open "DBQ="&server.mappath("db1.mdb")&";DRIVER={Microsoft Access Driver (*.mdb)}"
set rs=createobject("adodb.recordset")
rs.open "select * from file where id="&photoid&"",conn,1,1
contentType = "image/gif"
nFieldSize = RS("photo").ActualSize
response.contentType = contentType
response.BinaryWrite RS("photo").GetChunk(nFieldSize)
rs.close
set rs=nothing
%>Top
12 楼redfox33(豆子)回复于 2002-08-24 18:23:34 得分 0
不可思议,在我这边用你的代码还是能显示阿。
我在试试,等一下好吗?
'photo.asp--
Top
13 楼redfox33(豆子)回复于 2002-08-24 18:30:27 得分 0
谢谢,成功了!送分Top
14 楼redfox33(豆子)回复于 2002-08-24 18:32:00 得分 0
很感谢你能给不厌其烦的给我解答,并做测试。Top




