즉, 브라우저에서 특정 파일을 열지 않고 사용자에게 직접 다운로드하라는 메시지가 표시됩니다. 다음 코드를 ASP 파일에 복사 한 후에는 HTML 및 JavaScript 클라이언트 코드와 같은 페이지에 비 ASP 코드를 추가하지 마십시오.
코드 사본은 다음과 같습니다.
<%
'------------------------------------------
응답 .buffer = true
Dimstrfilepath, strfilesize, strfilename
constadtypebinary = 1
strfilepath = "Filepath"
strfilesize = ... 파일 크기, 선택 사항
strfilename = "파일 이름"
응답
'8 ************************************ 8
'서버에 MDAC2.6 또는 MDAC2.7을 설치해야합니다.
'8 ************************************ 8
setobjstream = server.createobject ( "adodb.stream")
objstream.open
objstream.type = adtypebinary
objstream.loadfromfilestfilepath
strfiletype = lcase (오른쪽 (strfilename, 4)) '파일 확장 스테이션. 역
'파일 확장에 의한 컨텐츠 유형을 판단합니다
SelectCasestFileType
케이스 ".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
'핸드 라이브 로이 파일
contentType = "Application/Octet-stream"
EndSelect
response.addheader "Content-Disposition", "첨부 파일; filename = strfilename
response.addheader "Content-Length", Strfilesize
Response.charset = "UTF-8" '고객 브라우저의 문자 세트 UTF-8
응답 .ContentType = ContentType
응답 .BinaryWriteObjStream.Read
응답. 플러시
objstream.close
setobjstream = 아무것도
%>