savedoc.asp
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:2k
- <%@Language="VBScript"%>
- <SCRIPT language="VBScript" runat="Server">
- Dim strReturnString,sFileName,sRelativePath
- '为了增强安全性,开发者可增加验证当前用户的功能,例如通过Session等
- '防止用户自己写客户端脚本向savedoc.asp提交非法文件
- ' 保存数据流到文件
- Function SaveFile(sFilePath,sContent)
- On Error Resume Next
- Dim oStream
- Set oStream = Server.CreateObject("ADODB.Stream")
- oStream.Type = 1
- oStream.Open
- oStream.Write sContent
- oStream.SaveToFile sFilePath, 2
-
- oStream.Close
- Set oStream = Nothing
- SaveFile = True
- If Err.number <> 0 Then
- SaveFile = False
- End If
- End Function
- Sub readAndSaveFile()
- On Error Resume Next
- Dim i
- Dim sFileContent
- Dim oXML
- Set oXML = Server.CreateObject("Msxml2.DOMDocument")
- oXML.async = false
- oXML.load Request
- 'sFileContent 是 word二进制流,此流可以保存成文件,也可以保存到数据库。
- sFileContent = oXml.documentElement.childNodes.item(0).nodeTypedValue
- 'FileName和RelativePath区分大小写
- sFileName = oXml.documentElement.childNodes.item(0).Attributes.getNamedItem("FileName").Text
- sRelativePath= oXml.documentElement.childNodes.item(0).Attributes.getNamedItem("RelativePath").Text
-
- '得到文件扩展名
- Dim intP, strFileExName
- intP = InStrRev(sFileName, ".")
- strFileExName = Mid(sFileName, intP)
- '接受doc、ppt和xls类型文件。开发者可增加接受其他类型文件
- if strFileExName = ".doc" or strFileExName = ".xls" or strFileExName = ".ppt" or strFileExName = ".wps" then
- SaveFile server.mappath(".") & "" & sRelativePath & sFileName, sFileContent
- end if
- Set oXml = Nothing
- If Err.number <> 0 Then
- strReturnString = "-1"
- End If
- End Sub
- '更新数据库中的文件修改时间
- Sub UpdateTime()
- Dim conn,dbpath
- Set conn=Server.CreateObject("ADODB.Connection")
- dbpath=Server.MapPath("../demodata/soademo.mdb")
- conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &dbpath
- dim strsql
- '********************************************************************
- ' 读数据库相关操作
- strsql="update word set submitTime='" & now() & "' where fileName='" & sFileName &"'"
- conn.execute(strsql)
- conn.Close
- ' 释放数据库连接对象
- set conn=nothing
- end sub
- '执行文件
- readAndSaveFile
- If strReturnString = "-1" Then
- Response.write("Save Error!")
- Else
- 'UpdateTime ' 如果您需要更新文件列表中"修改时间" ,就执行此过程.
- Response.write("Save OK.")
- End If
- </SCRIPT>