ASP in IE browser to download the various types of files on the implementation of the method _ Application techniques

Source: Internet
Author: User
The user is prompted to download the file directly instead of the browser. Note that after copying the following code into an ASP file, do not add some non-ASP code to the page: code such as HTML and JavaScript client.
Copy Code code as follows:

<%
'--------------------------------------------
Response.Buffer = True
Dim strFilePath, Strfilesize, strFileName
Const adTypeBinary = 1
strFilePath = "File path"
Strfilesize = ... File size, optional
strFileName = "FileName"
Response.Clear
' 8*******************************************8
' Need to install MDAC 2.6 or MDAC2.7 on your server
' 8*******************************************8
Set objstream = Server.CreateObject ("ADODB. Stream ")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
Strfiletype = LCase (Right (strFileName, 4)) ' File name extension station. Long. Station
' Judge content-types by file name extension
Select Case Strfiletype
Case ". asf"
ContentType = "VIDEO/X-MS-ASF"
Case ". avi"
ContentType = "Video/avi"
Case ". Doc"
ContentType = "Application/msword"
Case ". zip"
ContentType = "Application/zip"
Case ". xls"
ContentType = "Application/vnd.ms-excel"
Case ". gif"
ContentType = "Image/gif"
Case ". jpg", "JPEG"
ContentType = "Image/jpeg"
Case ". wav"
ContentType = "Audio/wav"
Case ". mp3"
ContentType = "Audio/mpeg3"
Case ". mpg", "MPEG"
ContentType = "Video/mpeg"
Case ". rtf"
ContentType = "Application/rtf"
Case ". htm", "html"
ContentType = "Text/html"
Case ". asp"
ContentType = "Text/asp"
Case Else
' Handle all other Files
ContentType = "Application/octet-stream"
End Select
Response.AddHeader "Content-disposition", "attachment"; Filename= strFileName
Response.AddHeader "Content-length", strfilesize
Response.Charset = "UTF-8" client browser's character set UTF-8
Response.ContentType = ContentType
Response.BinaryWrite Objstream.read
Response.Flush
objStream.Close
Set objstream = Nothing
%>

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.