推荐使用xmlhttp方法,把word文档经base64编码,存到一个xml文件中,使用xmlhttp传到服务器,直接存到数据库,使用时解析出来。至于文件名等作为一个字段存到数据库,与正文对应好就行了。这种方式适用于http方式上传,不知你用什么写程序,下面给出vb的例子作参考: Option Explicit
Dim oDoc As DOMDocument
Dim DOCINPATH As String
Dim XMLOUTPATH As String
Dim DOCOUTPATH As String Public Function sentxml(ByVal xmlfile As String, ByVal url As String, xmlname As String) As Integer
''''''''''''''''''''''''''''''''''''''''''''
'Dim conn As New ADODB.Connection
'Dim rs As New ADODB.Recordset
'Dim rs2 As New ADODB.Recordset
'Dim rs3 As New ADODB.Recordset
'Dim conn2 As New ADODB.Connection
'conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=test;Data Source=TTINFO"
'conn.Open
'conn.CursorLocation = adUseClient
'rs.ActiveConnection = conn
'rs.Open "select * from img where id=100"
'Dim da As Variant
'da = rs.Fields("img")
''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim oEle As IXMLDOMElement
Dim oRoot As IXMLDOMElement
Dim oNode As IXMLDOMNode
'DOCINPATH = App.Path & xmlfile
XMLOUTPATH = App.Path & "\" & xmlname '"\XmlOuput.xml"
Call ReleaseObjects
Set oDoc = New DOMDocument
oDoc.resolveExternals = True
'' Create processing instruction and document root
Set oNode = oDoc.createProcessingInstruction("xml", "version='1.0'")
Set oNode = oDoc.insertBefore(oNode, oDoc.childNodes.Item(0))
'' Create document root
Set oRoot = oDoc.createElement("Root")
Set oDoc.documentElement = oRoot
oRoot.setAttribute "xmlns:dt", "urn:schemas-microsoft-com:datatypes" '' Add a few simple nodes with different datatypes
Set oNode = oDoc.createElement("Document")
oNode.Text = "Demo"
oRoot.appendChild oNode
Set oNode = oDoc.createElement("CreateDate")
oRoot.appendChild oNode
Set oEle = oNode
'' Use DataType so MSXML will validate the data type
oEle.dataType = "date"
oEle.nodeTypedValue = Now
Set oNode = oDoc.createElement("bgColor")
oRoot.appendChild oNode
Set oEle = oNode
'' Use DataType so MSXML will validate the data type
oEle.dataType = "bin.hex"
oEle.Text = &HFFCCCC
Set oNode = oDoc.createElement("Data")
oRoot.appendChild oNode
Set oEle = oNode
'' Use DataType so MSXML will validate the data type
oEle.dataType = "bin.base64"
'' Read in the data
oEle.nodeTypedValue = ReadBinData(xmlfile)
'' Save xml file
oDoc.Save XMLOUTPATH
'**********************************************
Dim strA As String, szFile As String, m_szUpFile As String
'm_szUpFile = "http://localhost/sign/getupFile.asp?penid=aaa" 'server端的ASP接受程序
'MsgBox XMLOUTPATH & " is created for you."
Dim xmlHttp As New MSXML2.xmlHttp
xmlHttp.Open "POST", url, False
xmlHttp.setRequestHeader "CONTENT-TYPE", "text/xml"
xmlHttp.send oDoc
' 显示服务器返回的信息
Debug.Print xmlHttp.responseText
If xmlHttp.Status = 200 Then
sentxml = 1
Else
sentxml = 0
End If
'MsgBox sentxml
Set xmlHttp = Nothing
Set oDoc = Nothing End Function Function ReadBinData(ByVal strFileName As String) As Variant
Dim lLen As Long
Dim iFile As Integer
Dim arrBytes() As Byte
Dim lCount As Long
Dim strOut As String ''Read from disk
iFile = FreeFile()
Open strFileName For Binary Access Read As iFile
lLen = FileLen(strFileName)
ReDim arrBytes(lLen - 1)
Get iFile, , arrBytes
Close iFile ReadBinData = arrBytes
End Function
'
'Private Sub WriteBinData(ByVal strFileName As String)
' Dim iFile As Integer
' Dim arrBuffer() As Byte
' Dim oNode As IXMLDOMNode
'
' If Not (oDoc Is Nothing) Then
'
''' Get the data
' Set oNode = oDoc.documentElement.selectSingleNode("/Root/Data")
'
''' Make sure you use a byte array instead of variant
' arrBuffer = oNode.nodeTypedValue
'
''' Write to disk
'
' iFile = FreeFile()
' Open strFileName For Binary Access Write As iFile
' Put iFile, , arrBuffer
' Close iFile
'
' End If
'
'End Sub
'
'Private Sub Command2_Click()
'
' DOCOUTPATH = App.Path & "\DocOutput.jpg"
'
' Set oDoc = New DOMDocument
'
' If oDoc.Load(XMLOUTPATH) = True Then
' '' Save the Doc as another file
' WriteBinData DOCOUTPATH
'
' MsgBox DOCOUTPATH & " is created for you."
' Else
' MsgBox oDoc.parseError.reason
' End If
'End Sub Private Sub Form_Unload(Cancel As Integer)
ReleaseObjects
End Sub Private Sub ReleaseObjects()
Set oDoc = Nothing
End Sub 以上代码实现了读取文件、上传文件,下面是服务器端解析用的asp文件: 贴不上了,见下一个贴子 |