ASP

本类阅读TOP10

·asp常用数据库连接方法和技巧
·无组件生成BMP验证码
·一些常用的辅助代码 (网络收藏)
·JavaScript实现的数据表格:冻结列、调整列宽和客户端排序
·VisualStudio.NET_2003及其 MSDN 下载地址
·ASP模拟MVC模式编程
·图片以二进制流输出到网页
·MD5加密算法 ASP版
·ASP.NET编程中的十大技巧
·改进 ASP 的字符串处理性能

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
把存储在SQL7的image字段的文件下载到客户端的ASP源代码

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

把存储在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
%>

 




相关文章

相关软件