把存储在SQL7的image字段的文件下载到客户端的ASP源代码

    技术2022-05-11  75

    把存储在SQL7的image字段的文件下载到客户端的ASP源代码 

    文 件 名:download.asp 使用方法:download.asp?fid=xxx说  明:把SQL7的image字段存储的文件下载到客户端数据库结构:[表名]tabimage {fid int not null;filename varchar(100) not null;filecontent image not null}fid:文件id [PK];filename:文件名;filecontent:文件二进制内容

    <%Response.Buffer=Truevarfileid = Request("fid")If varfileid="" Then   Response.write "没有指定下载文件ID。"   Response.EndEnd If

    OpenDB connSQL = "SELECT filename,filecontent FROM tabimage WHERE fid=" & varfileidSet rs = conn.Execute(SQL)If Not rs.Eof Then   varfilename = rs("filename")   varfilesize=rs("filecontent").ActualSize   varcontent = rs("filecontent").GetChunk(varfilesize)   Response.ContentType = "*/*"   Response.AddHeader "Content-Length",varfilesize   Response.AddHeader "Content-Disposition", "attachment;filename=""" & varfilename & """"   Response.binarywrite varcontentEnd Ifrs.CloseSet rs = Nothingconn.CloseSet conn = NothingResponse.End

    '连接数据库通用过程Sub OpenDB (ByRef conn)    Set conn = Server.CreateObject("ADODB.Connection")        conn.provider="sqloledb"        conn.ConnectionString = "driver={SQL Server};server=xxx.xxx.xxx.xxx;uid=myusername;pwd=mypassword;database=mydatabase"        conn.OpenEnd Sub%>

     


    最新回复(0)