That is, it directly prompts the user to download rather than open certain files by the browser. Note that after copying the following code to the ASP file, do not add some non-ASP code to the page: such as HTML and javascript client code.
The code copy is as follows:
<%
'--------------------------------------------
Response.Buffer=True
DimstrFilePath, strFileSize, strFileName
ConstadTypeBinary=1
strFilePath="FilePath"
strFileSize=...file size, optional
strFileName="File Name"
Response.Clear
'8************************************************8
'Requires MDAC2.6 or MDAC2.7 to be installed on your server
'8************************************************8
SetobjStream=Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type=adTypeBinary
objStream.LoadFromFilestrFilePath
strFileType=lcase(Right(strFileName,4))' file extension station.long. station
'Judge Content-Types by file extension
SelectCasestrFileType
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"
CaseElse
'HandleAllOtherFiles
ContentType="application/octet-stream"
EndSelect
Response.AddHeader"Content-Disposition","attachment;filename=strFileName
Response.AddHeader"Content-Length",strFileSize
Response.Charset="UTF-8"'Customer Browser's Character Set UTF-8
Response.ContentType=ContentType
Response.BinaryWriteobjStream.Read
Response.Flush
objStream.Close
SetobjStream=Nothing
%>