Asp implements file download

Source: Internet
Author: User

 

Asp implements the file download function to download files directly without being opened by IE. Any files can be downloaded.

<Html>
<Head> <title> Download files without IE </title>
<Body>
<%
File = Request ("file ")
Call downloadFile (replace (file ,"",""),"/",""))
 
Function downloadFile (strFile)
'Make sure you are on the latest MDAC version for this to work
'-------------------------------------------------------------
If mid (strfile, 1, 5) = "http:" then
Response. write ("<a href =" & file & "> here" & file & "download </a> ")
'Response. redirect (file)
Exit function
End if
 
'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 the 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 browser
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
 
%>
</Body>
</Html>

Indicate the original site reprinted, please indicate from: www.111cn.net

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.