Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- join
- javascript 한글입력체크
- asp함수
- inner join
- MSSQL보안
- tempDB
- xmldom
- instr
- 인젝션
- 정규식
- jdbc driver
- 한글입력체크
- XML
- sql업데이트
- SPLIT
- array
- VARIABLE
- update
- 자바기초
- sql랭킹
- JavaScript
- VarType
- injection
- wap
- ERD
- 이미지가로길이
- sql순위
- WML
- FileSystemObject
- 이미지세로길이
Archives
- Today
- Total
3초기억력
ASP - binary 이미지 등 읽기 function 본문
<%
Function SaveBinaryData(FileName, ByteArray)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save binary data.
BinaryStream.Type = adTypeBinary
'Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.Write ByteArray
'Save binary data To disk
BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function
Function SaveTextData(FileName, Text, CharSet)
Const adTypeText = 2
Const adSaveCreateOverWrite = 2
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save text/string data.
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
If Len(CharSet) > 0 Then
BinaryStream.CharSet = CharSet
End If
'Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.WriteText Text
'Save binary data To disk
BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function
Function ReadBinaryFile(FileName)
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeBinary
'Open the stream
BinaryStream.Open
'Load the file data from disk To stream object
BinaryStream.LoadFromFile FileName
'Open the stream And get binary data from the object
ReadBinaryFile = BinaryStream.Read
End Function
Function ReadTextFile(FileName, CharSet)
Const adTypeText = 2
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
If Len(CharSet) > 0 Then
BinaryStream.CharSet = CharSet
End If
'Open the stream
BinaryStream.Open
'Load the file data from disk To stream object
BinaryStream.LoadFromFile FileName
'Open the stream And get binary data from the object
ReadTextFile = BinaryStream.ReadText
End Function
'// Scripting.FileSystemObject object
Function SaveBinaryDataTextStream(FileName, ByteArray)
'Create FileSystemObject object
Dim FS: Set FS = CreateObject("Scripting.FileSystemObject")
'Create text stream object
Dim TextStream
Set TextStream = FS.CreateTextFile(FileName)
'Convert binary data To text And write them To the file
TextStream.Write BinaryToString(ByteArray) '// 하단 참조
End Function
'// WinHttpRequest (XMLHTTP, ServerXMLHTTP) and remote files
Function BinaryGetURL(URL)
'Create an Http object, use any of the four objects
Dim Http
' Set Http = CreateObject("Microsoft.XMLHTTP")
' Set Http = CreateObject("MSXML2.ServerXMLHTTP")
Set Http = CreateObject("WinHttp.WinHttpRequest.5.1")
' Set Http = CreateObject("WinHttp.WinHttpRequest")
'Send request To URL
Http.Open "GET", URL, False
Http.Send
'Get response data As a string
BinaryGetURL = Http.ResponseBody
End Function
'// Convert a binary data (BinaryRead) to a string by VBS
'// 1. Use VBS MultiByte functions :
Function SimpleBinaryToString(Binary)
'SimpleBinaryToString converts binary data (VT_UI1 | VT_ARRAY Or MultiByte string)
'to a string (BSTR) using MultiByte VBS functions
Dim I, S
For I = 1 To LenB(Binary)
S = S & Chr(AscB(MidB(Binary, I, 1)))
Next
SimpleBinaryToString = S
End Function
Function BinaryToString(Binary)
'Antonin Foller, http://www.pstruh.cz
'Optimized version of a simple BinaryToString algorithm.
'// 절대 큰 파일은 읽지마라 -.-
Dim cl1, cl2, cl3, pl1, pl2, pl3
Dim L
cl1 = 1
cl2 = 1
cl3 = 1
L = LenB(Binary)
Do While cl1<=L
pl3 = pl3 & Chr(AscB(MidB(Binary,cl1,1)))
cl1 = cl1 + 1
cl3 = cl3 + 1
If cl3>300 Then
pl2 = pl2 & pl3
pl3 = ""
cl3 = 1
cl2 = cl2 + 1
If cl2>200 Then
pl1 = pl1 & pl2
pl2 = ""
cl2 = 1
End If
End If
Loop
BinaryToString = pl1 & pl2 & pl3
End Function
'// 2. Use ADODB.Recordset :
'// ADODB.Recordset lets you work with all supported VARIANT data types - also with binary and String data (VT_UI1 | VT_ARRAY, BSTR). It lets you convert between these two data formats :
Function RSBinaryToString(xBinary)
'Antonin Foller, http://www.pstruh.cz
'RSBinaryToString converts binary data (VT_UI1 | VT_ARRAY Or MultiByte string)
'to a string (BSTR) using ADO recordset
Dim Binary
'MultiByte data must be converted To VT_UI1 | VT_ARRAY first.
If vartype(xBinary)=8 Then Binary = MultiByteToBinary(xBinary) Else Binary = xBinary
Dim RS, LBinary
Const adLongVarChar = 201
Set RS = CreateObject("ADODB.Recordset")
LBinary = LenB(Binary)
If LBinary>0 Then
RS.Fields.Append "mBinary", adLongVarChar, LBinary
RS.Open
RS.AddNew
RS("mBinary").AppendChunk Binary
RS.Update
RSBinaryToString = RS("mBinary")
Else
RSBinaryToString = ""
End If
End Function
'// RSBinaryToString is not limitted by time - only by physical memory. The function is up to 100 times faster than MultiByte conversions - you can use it to convert up to 100MB data.
Function MultiByteToBinary(MultiByte)
'? 2000 Antonin Foller, http://www.pstruh.cz
' MultiByteToBinary converts multibyte string To real binary data (VT_UI1 | VT_ARRAY)
' Using recordset
Dim RS, LMultiByte, Binary
Const adLongVarBinary = 205
Set RS = CreateObject("ADODB.Recordset")
LMultiByte = LenB(MultiByte)
If LMultiByte>0 Then
RS.Fields.Append "mBinary", adLongVarBinary, LMultiByte
RS.Open
RS.AddNew
RS("mBinary").AppendChunk MultiByte & ChrB(0)
RS.Update
Binary = RS("mBinary").GetChunk(LMultiByte)
End If
MultiByteToBinary = Binary
End Function
'// 3. Use ADODB.Stream :
'// ADODB.Stream lets you work with String and binary data type. It lets you also convert between these two data formats :
Function Stream_BinaryToString(Binary, CharSet)
Const adTypeText = 2
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream 'As New Stream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save text/string data.
BinaryStream.Type = adTypeBinary
'Open the stream And write text/string data To the object
BinaryStream.Open
BinaryStream.Write Binary
'Change stream type To binary
BinaryStream.Position = 0
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
If Len(CharSet) > 0 Then
BinaryStream.CharSet = CharSet
Else
BinaryStream.CharSet = "us-ascii"
End If
'Open the stream And get binary data from the object
Stream_BinaryToString = BinaryStream.ReadText
End Function
%>
'플밍_ASP' 카테고리의 다른 글
ASP - 확장자 추출 하기 (0) | 2011.03.29 |
---|---|
ASP - 외부 URL 이미지 가져오기 (0) | 2011.03.25 |
ASP - ASP에서 바이너리 데이터를 읽고 표시하려면? (0) | 2011.03.25 |
ASP - 저장된 이미지를 바이너리로 변환하여 보여주는 소스 (0) | 2011.03.25 |
asp - 문자열 instr, mid 사용하여, 어디에서 어디까지 사이의 것들 뽑아내기 (0) | 2010.04.15 |
Comments