在线等!VB通过xml传输大于100M的文件
VB代码如下(网上查的)*******************************VB Class***************************************
Option Explicit
Dim XMLhttp As MSXML2.XMLHTTP30
Dim XMLDoc As MSXML2.DOMDocument30
Dim WebURL As String
Dim XMLRootNode As Variant
Private Sub Class_Initialize()
Set XMLhttp = New MSXML2.XMLHTTP30
Set XMLDoc = New MSXML2.DOMDocument30
End Sub
Public Sub Initialize()
XMLDoc.loadXML "<root/>"
Set XMLRootNode = XMLDoc.documentElement
End Sub
Public Property Let SetWebURL(URL As String)
WebURL = URL
End Property
Public Sub AddaFile(filaPath As String, fileName As String)
Dim fileNum As Integer
Dim btArr() As Byte
Dim fileNameNode, fileContentNode, fileNode
Set fileNode = XMLDoc.createNode(1, "file", "")
XMLRootNode.appendChild (fileNode)
Set fileNameNode = XMLDoc.createNode(1, "filename", "")
fileNameNode.Text = fileName
fileNode.appendChild (fileNameNode)
Set fileContentNode = XMLDoc.createNode(1, "fileContent", "")
fileNode.appendChild (fileContentNode)
fileNum = FreeFile
Open filaPath & fileName For Binary Access Read As #fileNum
ReDim btArr(LOF(fileNum))
Get #fileNum, , btArr()
Close #fileNum
With fileContentNode
.dataType = "bin.base64"
.nodeTypedValue = btArr
End With
End Sub
Public Function HttpUpload() As Boolean
Dim strHeaders As String
HttpUpload = False
XMLhttp.open "POST", WebURL, False
XMLhttp.send XMLDoc
Debug.Print XMLhttp.responseText
If XMLhttp.responseText = "Upload successful!" Then
HttpUpload = True
End If
End Function
Private Sub Class_Terminate()
Set XMLhttp = Nothing
Set XMLDoc = Nothing
End Sub
服务器端代码如下:
<%@ LANGUAGE=VBScript%>
<% Option Explicit
Response.Expires = 0
dim ado_stream
dim xml_dom
Dim i
Dim UpPath
dim CurrentFileName
Dim oNodelist
Dim currNode
'注意:这个文件夹一定要存在的
UpPath = replace(Server.MapPath("Upload.asp"),"Upload.asp","UPfiles\")
set ado_stream = Server.CreateObject("ADODB.Stream")
set xml_dom = Server.CreateObject("MSXML2.DOMDocument")
xml_dom.load(request)
Set oNodelist = xml_dom.selectNodes("/root/file")
For i = 0 To oNodelist.length - 1
Set currNode = oNodelist.Item(i).selectSingleNode("filename")
CurrentFileName = currNode.Text
Set currNode = oNodelist.Item(i).selectSingleNode("fileContent")
ado_stream.Type = 1 ' 1=adTypeBinary
ado_stream.open
ado_stream.Write currNode.nodeTypedValue
ado_stream.SaveToFile UpPath & CurrentFileName,2 ' 2=adSaveCreateOverWrite
ado_stream.close
Next
set ado_stream = Nothing
set xml_dom = Nothing
Response.Write "Upload successful!"
%>
补充:VB , 基础类