明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

SQL7的image字段的文件下載到客戶端

[摘要]把存儲在SQL7的image字段的文件下載到客戶端的ASP源代碼 文 件 名:download.asp 使用方法:download.asp?fid=xxx說  明:把SQL7的image字段存儲的文件下載到客戶端數(shù)據(jù)庫結構:[表名]tabimage fid int not null;filenam...
把存儲在SQL7的image字段的文件下載到客戶端的ASP源代碼

文 件 名:download.asp
使用方法:download.asp?fid=xxx
說  明:把SQL7的image字段存儲的文件下載到客戶端
數(shù)據(jù)庫結構:[表名]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

'連接數(shù)據(jù)庫通用過程
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
%>