asp 二进制保存到数据库的图片读取出来要怎么下载图片到本地
<imgsrc=showimg.asp?number=<%=rs("number")%>>showimg.asp<%SetCn=server.CreateObject("...
<img src=showimg.asp?number=<%=rs("number")%> >
showimg.asp
<%
Set Cn=server.CreateObject("ADODB.connection")
Cn.ConnectionString="Driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("pic.mdb")
Cn.Open
Set Rs=Server.Createobject("ADODB.recordset")
Sql="SELECT IMG from T1 WHERE ID=" & Request("ID")
Rs.open Sql,Cn,1,1
Response.ContentType = "image/*"
Response.BinaryWrite Rs("IMG").getChunk(7500000)
Rs.Close
Set Rs=nothing
Set Cn=nothing
%> 展开
showimg.asp
<%
Set Cn=server.CreateObject("ADODB.connection")
Cn.ConnectionString="Driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("pic.mdb")
Cn.Open
Set Rs=Server.Createobject("ADODB.recordset")
Sql="SELECT IMG from T1 WHERE ID=" & Request("ID")
Rs.open Sql,Cn,1,1
Response.ContentType = "image/*"
Response.BinaryWrite Rs("IMG").getChunk(7500000)
Rs.Close
Set Rs=nothing
Set Cn=nothing
%> 展开
1个回答
展开全部
主要代码部分
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "select PicName,PicContent from Pic where ID="&ID
rs.Open sql,Conn,1,1
ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; filename="&rs("PicName")
Response.ContentType = ContentType
Response.BinaryWrite rs("PicContent")
Response.Flush
response.Clear()
rs.close
Set rs = nothing
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "select PicName,PicContent from Pic where ID="&ID
rs.Open sql,Conn,1,1
ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; filename="&rs("PicName")
Response.ContentType = ContentType
Response.BinaryWrite rs("PicContent")
Response.Flush
response.Clear()
rs.close
Set rs = nothing
追问
我想问 PicPath 是要怎么才行 是图片的路径吗
追答
应为 rs("PicContent").getChunk(7500000)
PicName 为保存在客户机跳出保存时的默认文件名,也可以为固定文件名
PicContent 为图片二进制内容
ID = Request("ID")
If IsNull(ID) Then
ID = 0
Else
ID = Trim(ID)
If IsNumeric(ID) Then
ID = CInt(ID)
Else
ID = 0
End If
End If
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "select PicName,PicContent from Pic where ID="&ID
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询