savestream.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)
- dim rs , sid
- Dim conn,dbpath
- On Error Resume Next
-
- sid = Request.QueryString("id")
- Set conn=Server.CreateObject("ADODB.Connection")
- dbpath=Server.MapPath("../demodata/soademo.mdb")
- conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &dbpath
- sql="select * from stream where ID = " & sid
- Set rs = Server.CreateObject("ADODB.Recordset")
- rs.Open sql,conn,3,2
-
- rs.Fields("Word").appendchunk sContent
- rs.update
-
- rs.close
- conn.close
- set rs=nothing
- set conn=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 = 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
- Dim saveok
- saveok = False
- intP = InStrRev(sFileName, ".")
- strFileExName = Mid(sFileName, intP)
- '接受doc、ppt和xls类型文件。开发者可增加接受其他类型文件
- if strFileExName = ".doc" or strFileExName = ".xls" or strFileExName = ".ppt" or strFileExName = ".wps" then
- saveok = SaveFile(server.mappath(".") & "" & sRelativePath & sFileName, sFileContent)
- end if
- Set oXml = Nothing
- If Err.number <> 0 or saveok = False Then
- strReturnString = "-1"
- End If
- End Sub
- '执行文件
- readAndSaveFile
- If strReturnString = "-1" Then
- Response.write("Save Error!")
- Else
- Response.write("Save OK.")
- End If
- </SCRIPT>