つまり、ブラウザによって特定のファイルを開くのではなく、ユーザーにダウンロードするように直接促します。次のコードをASPファイルにコピーした後、HTMLやJavaScriptクライアントコードなど、[非ASPコード]をページに追加しないでください。
コードコピーは次のとおりです。
<%
'----------------------------------------------------
Response.buffer = true
dimstrfilepath、strfilesize、strfilename
ConstadTypebinary = 1
strfilepath = "filepath"
strfilesize = ...ファイルサイズ、オプション
strfileName = "ファイル名"
Response.Clear
'8 ****************************************** 8
'サーバーにMDAC2.6またはMDAC2.7をインストールする必要があります
'8 ****************************************** 8
setobjstream = server.createObject( "adodb.stream")
objstream.open
objstream.type = adtypebinary
objstream.loadfromfilestrfilepath
strfiletype = lcase(right(strfilename、4)) 'ファイルエクステンションステーション.long。駅
'ファイル拡張機能によるコンテンツタイプを判断します
selectcasestrfiletype
ケース ".asf"
contentType = "video/x-ms-asf"
ケース ".avi"
contentType = "video/avi"
ケース ".doc"
contentType = "Application/MSWORD"
ケース ".zip"
contentType = "application/zip"
ケース ".xls"
contentType = "application/vnd.ms-excel"
ケース ".gif"
contentType = "image/gif"
ケース ".jpg"、 "jpeg"
contentType = "image/jpeg"
ケース ".wav"
contentType = "audio/wav"
ケース ".mp3"
contentType = "audio/mpeg3"
ケース ".mpg"、 "mpeg"
contentType = "video/mpeg"
ケース ".rtf"
contentType = "application/rtf"
ケース ".htm"、 "html"
contentType = "text/html"
ケース ".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" '顧客ブラウザのキャラクターセットUTF-8
Response.ContentType = contentType
respons.binarywriteobjstream.read
Response.Flush
objstream.close
setobjstream =何もない
%>