Upload. inc
<SCRIPT runat = server Language = VBScript>
Dim upfile_5xsoft_stream
Class upload_5xsoft
Dim form, file, version
Private sub class_initialize
Dim istart, ifilenamestart, ifilenameend, iend, vbenter, iformstart, iformend, thefile
Dim strdiv, mformname, mformvalue, mfilename, mfilesize, mfilepath, idivlen, mstr
Version = ""
If request. totalbytes <1 then exit sub
Set form = Createobject ("scripting. Dictionary ")
Set file = Createobject ("scripting. Dictionary ")
Set upfile_5xsoft_stream = Createobject ("ADODB. Stream ")
Upfile_5xsoft_stream.mode = 3
Upfile_5xsoft_stream.type = 1
Upfile_5xsoft_stream.open
Upfile_5xsoft_stream.write request. binaryread (request. totalbytes)
Vbenter = CHR (13) & CHR (10)
Idivlen = instring (1, vbenter) + 1
Strdiv = substring (1, idivlen)
Iformstart = idivlen
Iformend = instring (iformstart, strdiv)-1
While iformstart <iformend
Istart = instring (iformstart, "name = """)
Iend = instring (istart + 6 ,"""")
Mformname = substring (istart + 6, iEnd-iStart-6)
Ifilenamestart = instring (iend + 1, "filename = """)
If ifilenamestart> 0 and ifilenamestart <iformend then
Ifilenameend = instring (ifilenamestart + 10 ,"""")
Mfilename = substring (ifilenamestart + 10, iFileNameEnd-iFileNameStart-10)
Istart = instring (ifilenameend + 1, vbenter & vbenter)
Iend = instring (istart + 4, vbenter & strdiv)
If iend> istart then
Mfilesize = iEnd-iStart-4
Else
Mfilesize = 0
End if
Set thefile = new fileinfo
Thefile. filename = getfilename (mfilename)
Thefile. filepath = getfilepath (mfilename)
Thefile. filesize = mfilesize
Thefile. filestart = istart + 4
Thefile. formname = formname
File. Add mformname, thefile
Else
Istart = instring (iend + 1, vbenter & vbenter)
Iend = instring (istart + 4, vbenter & strdiv)
If iend> istart then
Mformvalue = substring (istart + 4, iEnd-iStart-4)
else
mformvalue = ""
end if
form. add mformname, mformvalue
end if
iformstart = iformend + idivlen
iformend = instring (iformstart, strdiv) -1
Wend
end sub
Private function substring (thestart, thelen)
Dim I, C, stemp
Upfile_5xsoft_stream.position = theStart-1
Stemp = ""
For I = 1 to thelen
If upfile_5xsoft_stream.eos then exit
C = ASCB (upfile_5xsoft_stream.read (1 ))
If C & gt; 127 then
If upfile_5xsoft_stream.eos then exit
Stemp = stemp & CHR (ASCW (chrb (ASCB (upfile_5xsoft_stream.read (1) & chrb (c )))
I = I + 1
Else
Stemp = stemp & CHR (c)
End if
Next
Substring = stemp
End Function
Private function instring (thestart, varstr)
Dim I, j, BT, thelen, STR
Instring = 0
STR = tobyte (varstr)
Thelen = lenb (STR)
For I = thestart to upfile_5xSoft_Stream.Size-theLen
If I> upfile_5xsoft_stream.size then exit function
Upfile_5xsoft_stream.position = I-1
If ASCB (upfile_5xsoft_stream.read (1) = ASCB (midb (STR, 1) then
Instring = I
For J = 2 to thelen
If upfile_5xsoft_stream.eos then
Instring = 0
Exit
End if
If ASCB (upfile_5xsoft_stream.read (1) <> ASCB (midb (STR, J, 1) then
Instring = 0
Exit
End if
Next
If instring <> 0 Then exit function
End if
Next
End Function
Private sub class_terminate
Form. removeall
File. removeall
Set form = nothing
Set file = nothing
Upfile_5xsoft_stream.close
Set upfile_5xsoft_stream = nothing
End sub
Private function getfilepath (fullpath)
If fullpath <> "" then
Getfilepath = left (fullpath, limit Rev (fullpath ,"\"))
Else
Getfilepath = ""
End if
End Function
Private function getfilename (fullpath)
If fullpath <> "" then
Getfilename = mid (fullpath, limit Rev (fullpath, "\") + 1)
Else
Getfilename = ""
End if
End Function
Private function tobyte (STR)
Dim I, icode, C, ilow, ihigh
Tobyte = ""
For I = 1 to Len (STR)
C = mid (STR, I, 1)
Icode = ASC (c)
If icode <0 then icode = icode + 65535
If icode> 255 then
Ilow = left (hex (ASC (c), 2)
Ihigh = right (hex (ASC (c), 2)
Tobyte = tobyte & chrb ("& H" & ilow) & chrb ("& H" & ihigh)
Else
Tobyte = tobyte & chrb (ASCB (c ))
End if
Next
End Function
End Class
Class fileinfo
Dim formname, filename, filepath, filesize, filestart
Private sub class_initialize
Filename = ""
Filepath = ""
Filesize = 0
Filestart = 0
Formname = ""
End sub
Public Function saveas (fullpath)
Dim DR, errorchar, I
Saveas = 1
If trim (fullpath) = "" Or filesize = 0 or filestart = 0 or filename = "" Then exit function
If filestart = 0 or right (fullpath, 1) = "/" then exit function
Set DR = Createobject ("ADODB. Stream ")
Dr. mode = 3
Dr. type = 1
Dr. Open
Upfile_5xsoft_stream.position = FileStart-1
Upfile_5xsoft_stream.copyto DR, filesize
Dr. savetofile fullpath, 2
Dr. Close
Set DR = nothing
Saveas = 0
End Function
End Class
</SCRIPT>
Save. asp
<% Dim DSN, Conn
DSN = "driver = {SQL Server}; server = 127.0.0.1; uid = sa; Pwd =; database = Database"
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open DSN
%>
<% Dim file, file1, file2
File = trim (request. Form ("myface "))
File1 = trim (request. Form ("myface1 "))
File2 = trim (request. Form ("myface2 "))
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "insert into sfile (image, image1, image2) values ('" & file & "', '" & file1 & "', '" & file2 &"')"
Conn.exe cute (SQL)
Response. Redirect "OK. asp"
%>
This article comes from web development network Original article link: http://www.cncms.com.cn/asp/5006_6.htm