전 페이지 download.asp?file=파일명


download.asp 파일

<%
    file = request("file")
    '파일 이름

    Response.ContentType = "application/unknown"
    'ContentType 를 선언합니다.

    Response.AddHeader "Content-Disposition","attachment; filename=" & file 
    '헤더값이 첨부파일을 선언합니다.

    Set objStream = Server.CreateObject("ADODB.Stream")
    'Stream 을 이용합니다.

    objStream.Open
    '무엇이든 Set 으로 정의했으면 열어야 겠지요^^

    objStream.Type = 1

    objStream.LoadFromFile Server.MapPath("./upload/")&"\"& file
    '절대경로 입니다.

    download = objStream.Read
    Response.BinaryWrite download 
    '이게 보통 Response.Redirect 로 파일로 연결시켜주는 부분을 대신하여 사용된 것입니다.

    Set objstream = nothing 
    '초기화시키구요.

%>
출처 : http://www.taeyo.pe.kr/Lecture/20_TIps/Danny03.asp

매번 사용 하려고 하면 까먹는 코드

찾기도 짜증나서 적어 놓음


On Error Resume Next

'에러나는 코드 넣을것

If Request.Form("sbmtMultiply")<>"" then 'If multiply is clicked

   Value=Cint(Request.Form("txtA"))*Cint(Request.Form("txtB"))

End If

If Request.Form("sbmtDivide")<>"" then 'If divide is clicked

   Value=Cint(Request.Form("txtA"))/Cint(Request.Form("txtB"))

End If

If Err.number<>0 then

   If Err.number=11 then  '11 is the number that occurs for division by zero.

      Response.Write "This is a custom message. You cannot divide by zero."

      Response.Write "Please type a different value in the second textbox!<p>"

else

      Response.Write "An Error Has Occurred on this page!<BR>"

      Response.Write "The Error Number is: " & Err.number & "<BR>"

      Response.Write "The Description given is: " & Err.Description & "<BR>"

   End If

End If


에러에 대한 번호화 에러 번호에 대한 설명해줌

자세하게 나오지는 않음.

 그냥 에러 날때 무엇인지는 확인 가능 하나

몇번째 줄인지는 나오질 않음

분명 나타나게 하는게 있을거임

내가 모를뿐


'base64를 이용한 복호화 함수

	Dim enc64List()
	Dim dec64List()
	Dim  c, d, e , ascValue, i, n, ascArrayValue
	Dim  input(), output, ptr

Function initBase64()  '초기화 함수

	For i=0 To 25
		ReDim Preserve enc64List(i)
'Response.write Ubound(enc64List)&"
" 'CHR ==String.fromCharCode enc64List(Ubound(enc64List)) = Chr(65 + i) 'Response.write "i : "& i & ", enc64List : "& enc64List(i)&"]
" Next For i=0 To 25 ReDim Preserve enc64List(i+26) enc64List(Ubound(enc64List)) = Chr(97 + i) 'Response.write "i+26 : "& i+26 & ", enc64List : "& enc64List(i+26)&"]
" Next For i=0 To 9 ReDim Preserve enc64List(i+26+26) enc64List(Ubound(enc64List)) = Chr(48 + i) 'Response.write "i+26+26 : "& i+26+26 & ", enc64List : "& enc64List(i+26+26)&"]
" Next ReDim Preserve enc64List(Ubound(enc64List)+1) enc64List(Ubound(enc64List)) = "+" ReDim Preserve enc64List(Ubound(enc64List)+1) enc64List(Ubound(enc64List)) = "/" 'Response.write "["&enc64List(ubound(enc64List)-1)&"]
" 'For i=0 To ubound(enc64List) ' Response.write "i : "& i & ", enc64List : "& enc64List(i)&"]
" 'next For i=0 To 127 ReDim Preserve dec64List(i) dec64List(Ubound(dec64List)) = -1 Next 'Response.write "["&ubound(dec64List)&"]
" For i=0 To 63 ReDim Preserve dec64List(i+127) 'dec64List[enc64List[i].charCodeAt(0)] = i; dec64List(Asc(Left(enc64List(i),1))) = i 'Response.write i & " : " &Asc(Left(enc64List(i),1)) & "
" Next End Function Function base64Decode(value) c=0 d=0 ascValue=0 ptr =0 n=0 output = "" initBase64() '초기화함수를 이용하여 디코더 함수 배열 초기화 'Response.write "

" 'Response.write "value : ["& value&"]
" 'input = Split(value, "") ' ""로 잘라서 input 배열 생성 ReDim input(Len(value)-1) 'asp split 은 "" 으로 자를 수 없어서 for 문 활용 For i=0 To Len(value)-1 input(i) = Mid(value, i+1,1) ' Response.write "input : ["& input(i)&"]
" Next 'Asc(value) ==charCodeAt() ascValue = Asc(Left(input(ptr),1)) '배열의 인덱스 값을 증가시키며 첫번째 문자의 아스키 값을 ascValue로 받는다 'Response.write "ascValue : ["& ascValue&"]
" ptr =ptr +1 ascArrayValue = dec64List(ascValue) 'Response.write "ascArrayValue : ["& ascArrayValue&"]
" If ascValue >= 0 And ascValue < 128 And ascArrayValue <> -1 Then if n Mod 4 = 0 Then 'c = ascArrayValue << 2 c = ascArrayValue * 2^2 'Response.write "n : " & n &", c : ["& c &"]
" ElseIf n Mod 4 = 1 Then 'c = c Or ( ascArrayValue >> 4 ) c = c Or ( ascArrayValue / 2^4 ) 'Response.write "n : " & n &", c : ["& c &"]
" 'd = ( ascArrayValue And 0x0000000F ) << 4 d = ( ascArrayValue And &HF ) * 2^4 'Response.write "n : " & n &", d : ["& d &"]
" ElseIf n Mod 4 = 2 Then 'd = d Or ( ascArrayValue >> 2 ) d = d Or ( ascArrayValue /2^2 ) 'Response.write "n : " & n &", d : ["& d &"]
" 'e = ( ascArrayValue And 0x00000003 ) << 6 e = ( ascArrayValue And &H3 ) * 2^6 'Response.write "n : " & n &", e : ["& e &"]
" Else e = e Or ascArrayValue End If n= n+1 if n Mod 4 = 0 Then output = output & CHR(c) &CHR(d) & CHR(e) 'Response.write "n : " & n &"output : ["& output&"]
" End If End If 'x >> n' 은 x / 2^n의 결과와 같다. 우측으로 비트를 n만큼 움직임 'x << n' 은 x * 2^n의 결과와 같다. Do While ubound(input) >= ptr '기존 value를 잘라서 가지고 있는 input 배열의 크기와 ptr이 같아 질때까지 'Response.write ptr &"
" ascValue = Asc(Left(input(ptr),1)) '배열의 ptr 값을 증가시키며 첫번째 문자의 아스키 값을 ascValue로 받는다 : asp ++ 지원을 하지 않아 다음줄에서 ptr 증가 ptr =ptr +1 ascArrayValue = dec64List(ascValue) If ascValue >= 0 And ascValue < 128 And ascArrayValue <> -1 Then if n Mod 4 = 0 Then 'c = ascArrayValue << 2 c = ascArrayValue * 2^2 ElseIf n Mod 4 = 1 Then 'c = c Or ( ascArrayValue >> 4 ) c = c Or ( ascArrayValue / 2^4 ) 'd = ( ascArrayValue And 0x0000000F ) << 4 d = ( ascArrayValue And &HF ) * 2^4 ElseIf n Mod 4 = 2 Then 'd = d Or ( ascArrayValue >> 2 ) d = d Or ( ascArrayValue /2^2 ) 'e = ( ascArrayValue And 0x00000003 ) << 6 e = ( ascArrayValue And &H3 ) * 2^6 Else e = e Or ascArrayValue End If n= n+1 if n Mod 4 = 0 Then output = output & CHR(c) &CHR(d) & CHR(e) 'Response.write "n : " & n &", output : ["& output&"]
" End If End If Loop 'output += (n % 4 == 3) ? String.fromCharCode(c) + String.fromCharCode(d) : ((n % 4 == 2) ? String.fromCharCode(c) : ""); If n Mod 4 =3 Then output = output &CHR(c) & CHR(d) Else If n Mod 4 = 2 Then output = output & CHR(c) Else output = output & "" End If End If base64Decode = output End Function 내가 만듬, 현재 블로그 스크립트 메뉴에 있는 base64 암호화 함수를 복호화 하는 function 이며 자바스크립트 base64Decode(value) 함수를 asp 용으로 바꾼 것임. 비트 연산자가 먹히지 않아서 조금 애먹음 사용 법은 파라미터를 넘기는 페이지에서 스크립트용 base64 암호화를 이용하여 암호화 한후 submit 하면 받는 페이지에서 asp function base64Decode(parameter) 를 이용 하여 복호화 반대로 하는 즉 asp 에서 암호화 -> 자바스크립트 복호화는 나중에 만들어야 할듯 참고할 사항은 스크립트로 암호화시 그 페이지에서 넘어가기 직전 암호화된 아이디가 input 태그에 노출 되므로 (비밀번호는 type이 password라 노출되지 않음) 넘길때 스크립트로 각 값을 hidden 태그에 저장하고 보여지는 input 태그에는 값을 없애는 방법으로 적용함 아.. 자바하고싶다 ㅠㅠㅠㅠ

'프로그래밍 > ASP / .NET' 카테고리의 다른 글

간단한 다운로드 소스  (0) 2014.08.07
asp 에러 노출 코드  (0) 2014.03.05
asp 에서 엑셀로 파일 다운로드 구현하기  (0) 2013.10.08
엑셀 출력 페이지의 최상단부에 다음 코드를 추가합니다.
 
<%
' 여기서 엑셀 파일명 지정
filename = "test"

Response.Buffer = TRUE
Response.ContentType = "application/vnd.ms-excel"

Response.AddHeader "Content-disposition","attachment;filename=" & filename & ".xls"
%>
 
위 코드 하단부에는 엑셀로 출력하기 원하는 데이터를 테이블 형태로 그려지게 합니다.
테이블 형태라는 것은 말 그대로 <TABLE> 태그를 사용하라는 것입니다.
 
완성된 위 페이지를 웹브라우저로 읽으면 브라우저가 엑셀 파일로 인식하게 됩니다.
 
실무에서 엑셀 출력 버튼을 클릭하면 새창을 띄워서 위 페이지를 출력하거나, 안보이는 IFRAME-x을 미리 준비해뒀다가 그 IFRAME-x에서 위 페이지로 이동하는 방식으로 사용하시면 됩니다.
===================================================================================
페이지 결과를 엑셀파일로 저장하고 싶을때...
페이지 상단에 아래와 같은 코드를 넣으면 됩니다.
 
즉 웹브라우져에게 ContentType 를 엑셀이라고 알려주면 저장하거나 바로 웹브라우져에서 엑셀을 보여주거나
사용자의 설정에 따라 다르게 보여줄겁니다.
 
 Response.Buffer = False
 Response.Expires=0
 
 FileName = "저장될 파일이름" 

 Response.AddHeader "Content-Disposition","attachment;filename=" & server.URLPathEncode(FileName) & ".xls" '한글 인코딩 깨지지 않게 보존
 Response.ContentType = "application/vnd.ms-excel"  '''= 엑셀로 출력
 Response.CacheControl = "public"
 
그외
 
엑셀 : application/vnd.ms-excel
워드 : application/vnd.ms-word
파워포인트 : application/vnd.ms-powerpoint
 
 
덧 : Response.Buffer = False 와 Response.CacheControl = "public" 의 역할은 데이터를 버퍼링 하지 않고
바로 다운로드 창이 떠서 저장하기를 누르면 그때 데이터를 받아오도록 하는 기능입니다.


출처 : http://l2j.co.kr/1205

'프로그래밍 > ASP / .NET' 카테고리의 다른 글

간단한 다운로드 소스  (0) 2014.08.07
asp 에러 노출 코드  (0) 2014.03.05
base64 자바스크립트 암호화, asp 복호화  (2) 2014.03.05

+ Recent posts