ブラウザのアドレスバーでは、ドキュメントまたはXLSまたはJPGファイルのURLパスを直接入力すると、ファイルがブラウザに直接表示されます。多くの場合、ユーザーがダウンロードできるダウンロードプロンプトボックスを直接ポップアップしたいと考えています。私たちは何をすべきですか?ここに2つの方法があります。
1.サーバーのIIを設定し、Docなどの接尾辞名をマップします。
2.クライアントに送信するときにContentTypeを設定します。
方法2については、以下で詳しく説明しています
プログラムコード:
<%respons.buffer = true response.clear dim url dim fso、fl、flsize dim dname dim dname dim objstream、contenttype、flname、isre、url1 '************************************************************************ '********************************************************************************************************************************** "" then' and 'and' '******************************************* url = server.mappath( "/")& "/"&dname '************************************************** end* end* end fso = server.createobject( "scripting.filesemoobject")fl = fl = fso.getfile = fl.isize set fl.nama objstream = server.createobject( "adodb.stream")objstream.open objstream.type = 1 objstream.loadfromfile url select case lcase(右(flname、4))ケース ".asf" contenttype = "video/x-ms-asf" case "。 "application/msword" .zip "contentType =" application/zip "case" .xls "contentType =" application/vnd.ms-excel "。 = "audio/mpeg3" case ".mpg"、 "mpeg" contentType = "video/mpeg" case ".rtf" contentType = "application/rtf" case ".htm"、 "html" contenttype = "text/html" case ".txt" contenttype = "thex" endtetpe = "applicatepe =" response.addheader "Content-disposition"、 "添付ファイル。 filename = "&flname response.addheader" content-length "、flsize response.charset =" utf-8 "response.contenttype = contentType response.binarywrite objstream.read response.flush response.clear()objstream.close set objstream = Nothing%>
ダウンロードとして次のアイテムを保存すると、<aherf = "http://xxx.xx.com/download.asp?n=file.doc">ダウンロード!</a>を使用して、同じディレクトリにfile.docをダウンロードできます!
しかし、ここでは、URLにfile.docパスを直接書き込むことが安全ではないという問題があるため、解決策はデータベースにfile.docパスを保存し、データベースの検索後にパスを取得することです。
このプログラムの開始時に判断を追加する場合:
If strument(request.servervariables( "http_referer")、 "http:// your domain name")= 0 then Response.End End if
他の人がリンクを盗むのを防ぐことができます。