一个图片数据的存和取的示例

王朝other·作者佚名  2006-12-16
窄屏简体版  字體: |||超大  

图片数据存入数据库:

sqlstr="select * from "&tbname&" where id is null"

set rs=server.createobject("adodb.recordset")

rs.Open sqlstr,conn,1,3

rs.AddNew ()

rs("title")=title

rs("filename")=filename

rs("filetype")=filetype

rs("thelevel")=thelevel

rs("uploaddate")=date()

rs("uploadip")=request.ServerVariables("REMOTE_ADDR")

rs("contenttype")=contenttype

rs("data").AppendChunk (binstr)

rs("size")=size

rs("offset")=offset

rs.Update

rs.Close()

读取显示:

rs.Open sqlstr,conn,3

if not rs.EOF then

contenttype=rs("contenttype")

binstr=rs("data").GetChunk(rs("size")+rs("offset"))

if rs("offset")=1 then

binstr=midb(binstr,2)

end if

if instr(contenttype,"text/")=1 or _

instr(contenttype,"image/")=1 or _

instr(contenttype,"application/msword")=1 then

response.contenttype=trim(contenttype)

response.binarywrite binstr

else

response.addheader "Content-Disposition","attachment;filename="""&rs("filename")&""""

response.contenttype=trim(contenttype)

response.binarywrite binstr

end if

if request("preview")<>"yes" then

sqlstr="update "&tbname&" set downtimes=downtimes+1 where id="&fileid

conn.Execute sqlstr

end if

end if

说明:

对于超长的二进制数据(如图像数据)要使用fieldname.AppendChunk() 和fieldname.GetChunk()来读写。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航