아는 것이 좋은 것이다.

[ASP] 이미지 가져오기(참고) 본문

ASP

[ASP] 이미지 가져오기(참고)

start0 2014. 4. 24. 21:56

 

<%
'### Xml 이미지 시작 ###

Function Image_DisPlay(imgPath, numKind)

Randomize()
Dim numID : numID = Int((Rnd() * 1000) + 1)  '랜덤ID
Dim FileFormat : FileFormat = UCase(Mid(imgPath,InStrrev(imgPath, ".") + 1)) '확장자

SavePath = Server.MapPath("/") & "\Upload\XmlImg\"     '폴더경로
FileName = numID & "." & FileFormat   '로컬에 저장될 파일명


'이미지 가져오기
Set Http= CreateObject("MSXML2.ServerXMLHTTP")
  Http.Open "GET", imgPath, false
  Http.Send()
  binData = Http.ResponseBody
Set Http = Nothing


'이미지 저장
Set Stream = CreateObject("ADODB.Stream")
  Stream.open()
  Stream.type = 1
  Stream.Write binData
  Stream.SaveToFile SavePath & FileName, 2
Set Stream = Nothing


'이미지 바로 출력
If numKind = 1 Then
  Response.BinaryWrite binData
'파일명 넘기기
Else
  Image_DisPlay = FileName
End If


End Function

'### Xml 이미지 끝 ###


'1번 호출
Call Image_DisPlay("http://cafethumb2.naver.net/data21/2007/2/11/281/123.jpg", 1)

 

'2번 호출
'imgPath = Image_DisPlay("http://cafethumb2.naver.net/data21/2007/2/11/281/123.jpg", 2)
'Response.Write "<img src='http://test.kr/Upload/XmlImg/" & imgPath & "'>"
%>

Comments