Download the file stored in the image field of SQL7 to the client's ASP source code

Source: Internet
Author: User
Tags table name
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
%>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.