asp存取数据库图片?
以下是代码:
入库代码(测试数据添加成功)
<!--#include file= "inc/conn.asp "-->
<%
Response.Buffer=true
'取得客户端送出的数据字节大小
formsize=Request.TotalBytes
'以二进制方式读取数据
formdata=Request.BinaryRead(formsize)
'去掉实际数据前、后的边界字符串行
bncrlf=chrb(13) & chrb(10)
divider=leftb(formdata,clng(instrb(formdata,bncrlf))-1)
datastart=instrb(formdata,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
'读出图象数据
mydata=midb(formdata,datastart,dataend)
set rs=server.CreateObject( "adodb.recordset ")
rs.Open "select * from pic where id is null ",conn,1,3
rs.AddNew
rs( "img ").appendchunk mydata
rs.Update
counts=rs.recordCount+1
rs.Close
%>
显示代码:
<!--#include file= "inc/conn.asp "-->
<%
set rs=server.CreateObject( "adodb.recordset ")
if id= " " then response.End
response.Expires=0
response.buffer=true
response.Clear()
sql= "select * from pic where id=1 "
set rs=conn.execute(sql)
response.ContentType= "image/jpg "
response.BinaryWrite rs( "img ")
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
没有错误,但就是显示不出来图片,请问各位是那出错了
------解决方案--------------------不要用select *,尽量的使用select img from pic where id=1
------解决方案--------------------现在很少有把图片存到数据库中的了