读取数据库中的图片,不能只做简单的读或写,还要经过二进制数据处理的,代码如下:
name = request("name")
response.Expires = 0
response.Buffer = True
response.Clear
sql="select Photo from zmb where name='" &name& "'"
set rs=server.CreateObject("adodb.recordset")
rs.cursorlocation=3
rs.open sql,conn,1,1
if not rs.eof and not rs.bof then
response.contentType = "image/jpeg"
TheSize=rs("carphoto").ActualSize
if TheSize > 0 then
response.BinaryWrite rs("carphoto").GetChunk(TheSize)
else
response.Write "图片读取错误"
end if
else
response.Write "该信息不存在"
end if
rs.close
set rs=nothing
response.End
把上面的代码保存为一个*.asp文件,然后在其他页面中引用它:
<img src="*.asp?name=xxxx" border=0>