當前位置:編程學習大全網 - 源碼下載 - 做壹個能生成TXT文件的網頁html

做壹個能生成TXT文件的網頁html

僅使用HTML是辦不到的。使用服務器腳本語言,如JSP、ASP、PHP等,是非常容易辦到的壹件事。以下是使用ASP來做這件事的關鍵代碼:

<%

Dim s

s = "show license 1"

s = s & vbCrLf & "show 1 license"

SaveEncodedTextFile("C:\aFile.txt", "utf-8", s)

%>

以上 SaveEncodedTextFile() 子過程(函數)就是專門用來保存文本文件的,其源代碼如下(也可以上 /blog/post/SaveTextFile.html 查看):

<%

' 保存文本文件

Function SaveEncodedTextFile(sFilePath, sCharset, s)

Dim oStream

Set oStream = Server.CreateObject("ADODB.Stream")

' 以文本模式

oStream.Type = 2

oStream.Mode = 3

If Len(sCharset) > 0 Then

On Error Resume Next

oStream.Charset = sCharset

If Err.number <> 0 Then

oStream.Charset = "_autodetect_all"

End If

On Error Goto 0

End If

oStream.Open

oStream.WriteText s

' 2 - adSaveCreateOverwrite

On Error Resume Next

oStream.SaveToFile sFilePath, 2

If Err.number <> 0 Then

SaveEncodedTextFile = False

Else

SaveEncodedTextFile = True

End If

On Error Goto 0

Set oStream = Nothing

End Function

%>

  • 上一篇:纏論是否屬於事後看都是對的理論,或者說事後諸葛亮,或者說馬後炮理論?
  • 下一篇:如何閱讀glibc源代碼
  • copyright 2024編程學習大全網