[ASP] ADODB.Stream을 이용한 파일 다운로드

2004. 5. 31. 20:31Scrapbook/개발 및 프로그래밍

반응형
[CODE]DownLoadList.asp <% strFileName="다운로드될파일명" %> <script language="javascript"> function down(flag) { if(flag != ""){ var goUrl = "./download.asp?strFileName=" + flag; location.href=goUrl; }else{ alert("다운로드파일이 존재하지 않습니다.확인하여 주십시오"); } } <html> <head> <title>다운로드</title> <style> BODY, TABLE, TR, TD, P{font-size:9pt;font-family:굴림;} </style> </head> <body> <p> <a href="javascript('<%=strFileName%>');"><%=strFileName%></a> </p> ================================================================================== Download.asp <% Response.Buffer = False Response.Expires = 0 Dim strFileName '// 파일이름 Dim FileSeq '// 파일번호 Dim strFilePath '// 파일의경로 strFileName = Request("strfilename") '### 파일명을 요청한다. '// 이곳에서 파일에 대한 다운로드권한을 적용할수있다. '// 이곳에서 파일의 다운로드 횟수를 증가시킬수있다. '// 이곳에서 파일존재여부를 체크할수있다.(이전페이지[DownLoadList.asp])에서 '// 체크해도 된다. strFilePath = Server.mapPath(".") '###현재 파일의 파일 경로 디렉토리 설정 '//문서정의타입을 알수없음으로 하게되면 무조건 다운로드시킨다. '//다운로드시킬 파일을 정의한다. Response.ContentType = "application/unknown" Response.AddHeader "Content-Disposition","attachment; filename=" & strFileName '### ADODB.Stream으로 스트림을 읽는다. ### Set objStream = Server.CreateObject("ADODB.Stream") objStream.Open objStream.Type = 1 objStream.LoadFromFile strFilePath & "\" & strFileName strFile = objStream.Read Response.BinaryWrite strFile Set objStream = Nothing ' 자세한 Stream의 상수 및 메소드는 개인이 각자 습득한다. ' 그것이 서로를 위한 것이다..^^; %>[/CODE]
반응형