savehtml.asp
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:2k
- <%@Language="VBScript"%>
- <SCRIPT language="VBScript" runat="Server">
- Dim strReturnString
- '保存数据流到文件
- 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 sFileContent, sFileName, sHtmlFolder, FileObj, PrefixPath, sRelativePath
- Dim oXML
- Set oXML = Server.CreateObject("Msxml2.DOMDocument")
- oXML.async = false
- oXML.load Request
- 'sFileContent 是 word二进制流,此流可以保存成文件,也可以保存到数据库。
- sFileContent = oXml.documentElement.childNodes.item(0).nodeTypedValue
- 'FileName,HtmlFolder和RelativePath区分大小写
- sFileName = oXml.documentElement.childNodes.item(0).Attributes.getNamedItem("FileName").Text
- sHtmlFolder = oXml.documentElement.childNodes.item(0).Attributes.getNamedItem("HtmlFolder").Text
- sRelativePath= oXml.documentElement.childNodes.item(0).Attributes.getNamedItem("RelativePath").Text
- PrefixPath = server.mappath(".") & ""
- '得到文件扩展名
- Dim intP, strFileExName
- intP = InStrRev(sFileName, ".")
- strFileExName = Mid(sFileName, intP)
- '接受html元素文件。开发者可增加其他类型文件。此处的判断是增强上传安全性
- if strFileExName = ".htm" or strFileExName = ".xml" or strFileExName = ".gif" _
- or strFileExName = ".jpg" or strFileExName = ".png" or strFileExName = ".wmz" _
- or strFileExName = ".mso" or strFileExName = ".wmf" or strFileExName = ".js" or strFileExName = ".css" then
- if sHtmlFolder <> "" Then
- set FileObj=Server.Createobject("Scripting.FileSystemObject")
- if Not FileObj.FolderExists(PrefixPath & sRelativePath & sHtmlFolder) then
- FileObj.CreateFolder(PrefixPath & sRelativePath & sHtmlFolder)
- end if
- sHtmlFolder = sHtmlFolder & ""
- end if
- SaveFile PrefixPath & sRelativePath & sHtmlFolder & sFileName, sFileContent
- end if
- Set oXml = Nothing
- If Err.number <> 0 Then
- strReturnString = "-1"
- End If
- End Sub
- '执行文件
- readAndSaveFile
- If strReturnString = "-1" Then
- Response.write("Save Error!")
- Else
- Response.write("Save OK.")
- End If
- </SCRIPT>