How to Implement ASP to download various files on the server in IE browser

Source: Internet
Author: User

That is, the user is prompted to download the file instead of opening some files in the browser. Note that the following Code After copying to an ASP file, do not add any non-ASP code on the page, such as the Code of the HTML and JavaScript clients. Copy code The Code is as follows: <%
'--------------------------------------------
Response. Buffer = true
Dim strfilepath, strfilesize, strfilename
Const adtypebinary = 1
Strfilepath = "file path"
Strfilesize =... file size, optional
Strfilename = "file name"
Response. Clear
'8 ************************************** * ***** 8
'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 extension site. Long. Site
'Determine content-types by File 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" 'character set UTF-8 for the client browser
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.