有事就给我打电话,拼命的打
首页 | 公司概况 | 新闻列表 | 产品列表 | 业务介绍 | 技术知识 | 论坛  
   
□ 站 内 搜 索 □
请输入查询的字符串:

 

[原创]关于断剑新闻系统1.1版中有网友说要生成时间文件夹的方法!(可以学习生成静态的文件夹)


发布时间:2005-3-20 被阅览数:63 次 作者:断剑

 

今天有网友告诉我说,问我怎么样让新闻系统每天都生成一个文件夹放当天加的文件!

新浪等一些大型门户网站是那样的!断剑新闻系统都叫的是简单系统,就是不想太复杂,文件夹建的多了,占空间也就多了,对一般的网友可是个负担哦,不过应那位朋友的建议,我还是帮他改了一下程序,现在贴出来让大家都学习学习

首先是mosave.asp   makeall.asp网友自已按着改吧!

<!--#include file="fn/conn.asp"-->
<!--#include file="fn/fso.asp"-->
<%
'此页为读取FSO文件做模板的,
'下面开始成员过滤,非管理员不能登陆此界面
'if session("admin")="" or session("step")<1 then
'response.redirect "admin_login.asp"
'end if
%>

<%

'这个fn/moban6.htm是模板所在的路径
okfile=fsow("fn/moban6.htm")

dtime=now()
filename1=getfilename(dtime) & ".htm"
'file1=server.mappath( "news" )
file1=CreateFolder(gettimefilename(date()))
file1=server.mappath(""&gettimefilename(date())&"")
file2=file1&"\"&filename1
author=request.form("d_author")
dtime=date()
artical=request.form("d_content")
title=request.form("d_title")
ttype=request.form("ttype")

okfile = replace(okfile,"title1",title)
okfile = replace(okfile,"author",author)
okfile = replace(okfile,"article",artical)
okfile = replace(okfile,"arttime",dtime)
 Set fso = Server.CreateObject("Scripting.FileSystemObject")
  Set fout = fso.Createtextfile(file2,true)
 fout.writeline okfile
fout.close

''''''''''''''''''''''''''''''''''''''
file3=gettimefilename(date())&"\"&filename1
set rs=Server.createObject("adodb.recordset")
strsql="select *from art_file"
rs.open strsql,conn,3,3
rs.addnew
rs("title")=title
rs("artical")=artical
rs("arttime")=dtime
rs("author")=author
rs("type")=ttype
rs("filename")=file3
rs.update
rs.close
response.write"添加完成!"
%>单击<a href='<%=file3%>'>查看</a>

 

包含文件conn.asp为数据库连接文件,不要改动

fso.sap放在fn文件夹下的

fso.asp

<%
'利用FSO直接读取模板
function fsow(filename)
set mfo=Server.CreateObject("Scripting.FileSystemObject")
set rtf=mfo.OpenTextFile(server.mappath(filename),1)
body=rtf.readall
fsow=body
end function
%>


<%
'生成文件夹
Function CreateFolder(Folder)
 Dim Fso, F
 Set Fso = Server.CreateObject("Scripting.FileSystemObject")
 If Fso.FolderExists(Server.MapPath(Folder)) Then Exit Function
 Set F = Fso.CreateFolder(Server.MapPath(Folder))
 Set F = Nothing
 Set Fso = Nothing
End Function
%>

<%
'--------------以日期为文件名
function gettimefilename(d)
dim datetime,date1
datetime=cstr(d)
date1=datetime
gettimefilename=year(date1)&month(date1)&day(date1)
end function
%>
<%
'以时间日期为文件名
function getfilename(d)
dim datetime
datetime=cstr(d)
dim date1,time1
date1=split(d," ")(0)
time1=split(d," ")(1)
getfilename=year(date1)&month(date1)&day(date1)&hour(time1)&minute(time1)&second(time1)
end function
%>

 

呵,就是这样的了,有什么不足的地方,请大家提出来

 

 

由于没事,便把makeall.asp这个文件也改成了生成时间文件夹的,但是如果手工删除过文件且把以前生成的文件夹删除了的话就会报错,文件内容如下:

<!--#include file="fn/conn.asp"-->
<!--#include file="fn/fso.asp"-->
<%
'生成由时间文件夹存放的文件
'下面开始成员过滤,非超级管理员不能登陆此界面
'if session("admin")="" or session("step")<>8 then
'response.write "你不是超级管理员,不能批量更新!"
'response.end
'end if
%>
<html><head><title>批量生成HTML</title></head>
<body>

<%
dim dtime,filename1,i
i=0


strsql="select *from art_file"
set rs=conn.execute(strsql)

do while not rs.eof

'这个fn/moban6.htm是模板所在的路径
okfile=fsow("fn/moban6.htm")

 

'file1=server.mappath( "news" )

'file2=file1&"\"&rs("filename")
filename1=rs("filename")
file2=server.mappath(""&filename1&"")

title=rs("title")
dtime=rs("arttime")
author=rs("author")
artical=rs("artical")


okfile = replace(okfile,"title1",title)
okfile = replace(okfile,"author",author)
okfile = replace(okfile,"article",artical)
okfile = replace(okfile,"arttime",dtime)
 Set fso = Server.CreateObject("Scripting.FileSystemObject")
  Set fout = fso.Createtextfile(file2,true)
 fout.writeline okfile
fout.close
i=i+1
%>
更新完成<%=I%> :  <%=filename1%>,单击<a href='<%=filename1%>' target="_blank">查看</a><br>
<%
 rs.movenext
    loop
%>
</body>
</html>

 


上一篇: 痛打落水狗 AMD针对英特尔垄断可能提起诉讼 下一篇: 性感美女热辣表演 三星舞台吸引人

Copyright @ 2004-2008  http://www.koyee.com 断剑工作室版权所有
公司地址:江西南昌 电话:13879173467 邮编:330029
email:chenxueyan9999@163.com