브라우저의 주소 표시 줄에서 Doc 또는 XLS 또는 JPG 파일의 URL 경로를 직접 입력하면 파일이 브라우저에 직접 표시됩니다. 대부분의 경우 사용자가 다운로드 할 수 있도록 다운로드 프롬프트 상자를 직접 팝업하기를 희망합니다. 우리는 무엇을해야합니까? 두 가지 방법은 다음과 같습니다.
1. 서버의 IIS를 설정하고 Doc과 같은 접미사 이름을 매핑하십시오.
2. 클라이언트에게 보낼 때 ContentType를 설정하십시오.
방법 2는 아래에 자세히 설명되어 있습니다
프로그램 코드 :
<% Response.Buffer = true Response.Clear dim url Dim fso,fl,flsize dim Dname Dim objStream,ContentType,flName,isre,url1 '************************************************ The download file name passed in when the call Dname=trim(request("n")) '****************************************************************************************************************************** If Dname<>"" Then '*************************************************************** The server directory where the download file is stored is url=server.MapPath("/")&"/"&Dname '************************************************ End If Set fso=Server.CreateObject("Scripting.FileSystemObject") Set fl=fso.getfile(url) flsize=fl.size flName=fl.name Set fl=Nothing Set fso=Nothing %> <% set objstream = server.createobject ( "adodb.stream") objstream.open objstream.type = 1 objstream.loadfile URL Select Lase (right (flname, 4)). ASF "ContentType ="video/x-ms-asf "case".avi "contenttype ="video/avi ".doc".doc ".doc". "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 "contemttype".wav "audio/wav" ". = "Audio/MPEG3"CASE ".MPG", "MPEG"ContentType = "Video/MPEG"CASE ".RTF"ContentType = "Application/RTF"CASE ".HTM", "HTML"ContentType = "Text/Html"CASE ".TXT"ContectType = "electtype"elseptype = "select" "내용화", "첨부 파일; filename = "& flname response.addheader"content-length ", flsize response.charset ="utf-8 "response.contentType = contentType response.BinaryWrite objStream.Read.Flur () objStream.close set objstream = nothing % %>다음 항목을 다운로드로 저장하면 <aherf = "http://xxx.xxx.com/download.asp?n=file.doc"> 다운로드! </a>를 동일한 디렉토리에서 다운로드 할 수 있습니다!
그러나 여기서는 URL에 File.doc 경로를 직접 작성하는 것이 안전하지 않다는 데 문제가 있으므로 솔루션은 데이터베이스에 파일을 저장하고 데이터베이스를 검색 한 후 경로를 가져 오는 것입니다.
이 프로그램의 시작 부분에 판단을 추가하면 :
IF instr (request.servariables ( "http_referer"), "http : // 도메인 이름") = 0 그런 다음 응답. 엔드 if
다른 사람들이 자신의 링크를 훔치지 못하게 할 수 있습니다.