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
%>