访问统计 【FSO操作】[asp]

FileSystemObject 对象用于访问服务器上的文件系统。

FileSystem和TextStream对象可用于建立对文件系统的访问,并提供顺序访问文件的机制。FileSystem没有属性,只有两个方法,第一个方法是CreateTextFile方法,可以在宿主机上创建新的文本文件,并返回TextStream对象以提供对新创建文件的访问机制。第二个是OpenTextFile方法,用于打开文本文件供顺序访问并返回一个TextStream对象.

= = = = = = = = = = = 分 割 线 = = = = = = = = = = == = =

CreateTextFile 方法

定义和用法

CreateTextFile 方法可在当前文件夹中创建新的文本文件,并返回可用于读或写文件的 TextStream 对象。

语法:

FileSystemObject.CreateTextFile(filename[,overwrite[,unicode]])
FolderObject.CreateTextFile(filename[,overwrite[,unicode]])
参数描述
filename必需的。需创建文件的名称。
overwrite可选的。指示能否覆盖已有文件的布尔值。True 指示可覆盖文件,False 指示不能覆盖文件。默认是 True 。
unicode可选的。指示文件是作为 Unicode 还是 ASCII 文件来创建的布尔值。True 指示文件作为 Unicode 文件创建,而 False 指示文件被作为 ASCII 文件创建。默认是 False。

针对 FileSystemObject 对象的实例

<%
dim fs,tfile
set fs = Server.CreateObject( " Scripting.FileSystemObject " )
set tfile = fs.CreateTextFile( " c:\somefile.txt " )
tfile.WriteLine(
" Hello World! " )
tfile.close
set tfile = nothing
set fs = nothing
%>

= = = = = = = = = = = 分 割 线 = = = = = = = = = = == = =

OpenTextFile 方法

OpenTextFile 方法打开指定的文件,并返回可用来访问此文件的 TextStream 对象

语法

FileSystemObject.OpenTextFile(fname,mode,create,format)
参数描述
fname必需的。要打开的文件的名称。
mode可选的。如何打开文件。
  • 1=ForReading - 打开文件用于读取数据。您无法向此文件写数据。
  • 2=ForWriting - 打开文件用于写数据。
  • 8=ForAppending - 打开文件,并向文件的末尾写数据。
create可选的。设置如果文件名不存在,是否创建新文件。True 指示可创建新文件,而 False 指示新文件不会被创建。False 是默认的。
format可选的。文件的格式。
  • 0=TristateFalse - 以 ASCII 打开文件。默认。
  • -1=TristateTrue - 以 Unicode 打开文件。
  • -2=TristateUseDefault - 使用系统默认格式打开文件。

实例

<%
dim fs,f
set fs = Server.CreateObject( " Scripting.FileSystemObject " )
set f = fs.OpenTextFile(Server.MapPath( " testread.txt " ), 8 , true )
f.WriteLine(
" This text will be added to the end of file " )
f.Close
set f = Nothing
set fs = Nothing
%>

= = = = = = = = = = = 分 割 线 = = = = = = = = = = == = =

访问统计

ManageLogStat.asp

<table class="tableBorder" width="55%" border="0" align="center" cellpadding="5" cellspacing="1">
<form action="DelcontentStat.asp" method="post">
	<tr>
		<th width="50%">访问统计</th>
		<th>作弊参数</th>
	</tr>
	<tr>
		<td class="forumRow" align="center">
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("../count/count.txt"), 1)
Stat = f.ReadAll
Response.Write(Stat)
f.Close
Set f=Nothing
Set fs=Nothing
%>
		</td>
		<td align="center" class="forumRow">
		<input type="text" name="Stat" maxlength="20" value="<%=Stat%>" />
		</td>
	</tr>
	<tr>
	<td class="forumRow">
	</td>
	<td class="forumRow">
	<input type="submit" value="修改" />
	</td>
	</tr>
	</form>
</table>

DelContentStat.asp

<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject") 
set f=fs.CreateTextFile(Server.MapPath("../count/count.txt"),true)
Stat = request("Stat")
f.write(Stat)
f.close
set f=nothing
set fs=nothing
response.redirect request.servervariables("http_referer")
%>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值