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