簡單示範如何接收表單 POST 資料,以計數器命名檔案,將每筆資料存為獨立文字檔。
<FORM ACTION="saveinfo.asp" METHOD="post">
<!-- 任意輸入欄位 -->
<INPUT TYPE="submit" VALUE="Submit">
</FORM>
<%
Set fs = CreateObject("Scripting.FileSystemObject")
FolderPath = Server.MapPath("") & "/cgi-bin/messages143718"
Wcounter = FolderPath & "/counter.txt"
' 讀取/初始化計數器
If fs.FolderExists(FolderPath) Then
Set a = fs.OpenTextFile(Wcounter)
hits = CLng(a.ReadLine)
hits = hits + 1
a.Close
Else
fs.CreateFolder(FolderPath)
hits = 1
End If
' 更新計數器
Set a = fs.CreateTextFile(Wcounter, True)
a.WriteLine(hits)
a.Close
Set fs = Nothing
' 以計數器為檔名儲存表單資料
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(FolderPath & "\" & hits & ".txt")
For Each x In Request.Form
a.WriteLine(x & ": " & Request.Form(x))
Next
a.Close
Set a = Nothing
Set fs = Nothing
%>