Client | download | Source code to download the file stored in SQL7 image field to the client's ASP source code
FileName: download.asp
How to use: download.asp?fid=xxx
Description: Download the files stored in the image field of SQL7 to the client
Database structure: [table name]tabimage {FID int not null;filename varchar (MB) Not null;filecontent image not null}
FID: File ID [pk];filename: filename; filecontent: File binary content
<%
Response.buffer=true
Varfileid = Request ("FID")
If varfileid= "" Then
Response.Write did not specify the download file 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
' Connecting to a database common process
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
%>