当前位置: 首页 > 图文教程 > 网络编程 > ASP > SQL7的image字段的文件下载到客户端

ASP
用ASP编写网络传呼机
用ASP+CSS实现随机背景
ASP下载系统防盗链方法
用ASP编写下载网页中所有资源的程序
Request.ServerVariables应用
解决Asp程序的Server.CreateObject错误
ASP实现TCP端口扫描的方法
源码实例:ASP实现远程保存图片
用ASP+DLL实现WEB方式修改服务器时间
ASP使用MySQL数据库全攻略
ASP+SQL Server构建网页防火墙
教程/ASP 十天学会ASP之第二天
教程/ASP 十天学会ASP之第四天
教程/ASP 十天学会ASP之第五天
教程/ASP 十天学会ASP之第六天
教程/ASP 十天学会ASP之第七天
教程/ASP 十天学会ASP之第八天
教程/ASP 十天学会ASP之第九天
教程/ASP 十天学会ASP之第十天
关于学习ASP和编程的28个观点

ASP 中的 SQL7的image字段的文件下载到客户端


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 27 ::
收藏到网摘: n/a

  把存储在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=True
varfileid = Request("fid")
If varfileid="" Then
Response.write "没有指定下载文件ID。"
Response.End
End If

OpenDB conn
SQL = "SELECT filename,filecontent FROM tabimage WHERE fid=" & varfileid
Set 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 varcontent
End If
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
Response.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.Open
End Sub
%>