windows - classic asp 写入文件版本1, 简单的上传文件

访问量: 384

refer to:
https://stackoverflow.com/questions/2198810/creating-and-writing-lines-to-a-file

完整例子:(仅仅写)

<%

' Create The Object
Set FSO = CreateObject("Scripting.FileSystemObject")

' How To Write To A File
'Set File = FSO.CreateTextFile("c:\\webhosting\\data\\data\\bar.txt",True)
path = server.mappath("/") & "/" & "bar2.txt"
response.write("path: " & path)
Set File = FSO.CreateTextFile(path,True)
File.Write "Example String22"
File.Close

%>

上面的  server.mappath中,第一个参数 / 为当前目录, /data 表示当前目录下的data目录。 后面的 &"/" 不能省略

下面是一个完整的上传 asp 文件(通过提交表单达到上传的目的)

<%
response.write("current path: " & server.mappath("/"))

If request("file_name") <> "" Then
  Set FSO = CreateObject("Scripting.FileSystemObject")

  file_name = request("file_name")
  file_extension = request("file_extension")
  path = server.mappath("/") & "/" & file_name & "." & file_extension
  response.write("path: " & path)
  Set File = FSO.CreateTextFile(path,True)
  File.Write request("file_content")
  File.Close
End If

%>
<form method=POST>
  file name: <input type="text" name="file_name" placeholder="e.g. my_page"/> <br/>
  file ext : <input type="text" name="file_extension" placeholder="e.g. asp"/> <br/>
  content: <br/>
  <textarea name="file_content" style='width: 300px; height: 200px'>
  </textarea> 
<input type="submit" value="submit" /> </form>

订阅/RSS Feed

Subscribe