ASP implementation of File direct download code _ Application Techniques
Source: Internet
Author: User
<%@ Language=vbscript codepage=65001%>
<%
' Filename must be input
If Request ("Filename") = "" Then
Response.Write "Else
Call DownloadFile (replace (Request ("Filename", "\", ""), "/", ""))
Function DownloadFile (strfile)
' Make sure your are on the latest MDAC version of To work
' Get full path of specified file
strFileName = Server. MapPath (strfile)
' Clear the buffer
Response.Buffer = True
Response.Clear
' Create stream
Set s = Server.CreateObject ("ADODB.") Stream ")
S.open
' Set as Binary
S.type = 1
' Load in ' file
On Error Resume Next
' Check the file exists
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")
If not FSO. FileExists (strFileName) Then
Response.Write ("Response.End
End If
' Get length of file '
Set f = fso. GetFile (strFileName)
Intfilelength = F.size
S.loadfromfile (strFileName)
If Err Then
Response.Write ("Response.End
End If
' Send the headers to the users Browse
Response.AddHeader "Content-disposition", "attachment"; Filename= "&f.name
Response.AddHeader "Content-length", intfilelength
Response.Charset = "UTF-8"
Response.ContentType = "Application/octet-stream"
' Output the file to the ' browser
Response.BinaryWrite S.read
Response.Flush
' Tidy up
S.close
Set s = Nothing
End Function
End If
%>
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