ASP

ADODB.Stream을 이용한 파일다운로드 소스

귀찮은 여니씨 2008. 8. 28. 13:50
 

ADODB.Stream을 이용한 파일다운로드 소스

 

DownLoadList.asp

<%

   strFileName="다운로드될파일명"

%>

<script-x language="javascript-x">
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-x('<%=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의 상수 및 메소드는 개인이 각자 습득한다.

  ' 그것이 서로를 위한 것이다..^^;

  %>



- 출처 : http://flashcafe.org/bbs/board.php?bo_table=asp_study&wr_id=204&sca=&sfl=wr_subject&stx=%C6%C4%C0%CF%B4%D9%BF%EE%B7%CE%B5%E5&sop=and  -
이거도 참고
http://flashcafe.org/bbs/board.php?bo_table=asp_study&wr_id=250

개인적으로 이 사이트 괜찮네 ㅎㅎ
http://flashcafe.org/bbs/board.php?bo_table=asp_study