这是一个生成html的方法 makehtml.asp <% Option Explicit '随机码 function rndn() dim rndnum randomize rndnum=rnd*99+1 rndn=int(rndnum) end function '转换日期(年份) function chuageyear(shijian) dim s_year s_year=year(shijian) chuageyear=s_year end function
'转换日期(月份) function chuagemonth(shijian) dim s_month s_month=month(shijian) chuagemonth=s_month end function
'时间文件名(日期+随机码) function filename(shijian,rndmun) dim s_day,s_hour,s_min,s_sec,filen s_day=day(shijian) if s_day<10 then s_day="0"&s_day s_hour=hour(shijian) if s_hour<10 then s_hour="0"&s_hour s_min=minute(shijian) if s_min<10 then s_min="0"&s_min s_sec=second(shijian) if s_sec<10 then s_sec="0"&s_sec filen=s_day&s_hour&s_min&s_min&s_sec&rndmun filename=filen end function
'生成文件夹 function cfolder(times,pathname) dim fs set fs=server.createobject("Scripting.FileSystemObject") dim makeyear,makemonth,path path=pathname makeyear=server.mappath(path)&"\"&chuageyear(times) 'response.Write( makeyear) 'response.Write( not fs.FolderExists(makeyear)) 'response.Write(chuageyear(times)) 'response.End() if not fs.FolderExists(makeyear) then fs.CreateFolder(makeyear) '建立年份新文件夹 makemonth=makeyear&"\"&chuagemonth(times) if not fs.FolderExists(makemonth) then fs.createfolder(makemonth) '建立月份文件夹 cfolder=makemonth set fs=nothing end function
'生成html function makehtml(nowtime,body,pathname,rndnum) 'nowtime 文件的时间 'body 内容 'pathname 目录 文件夹 'rndnum 随机码 '以上可以从数据库读。 dim htmlname,txtname,write_one,filepath,fs,filez,isok,st,i,myfile isok=1 set fs=server.createobject("Scripting.FileSystemObject") htmlname=filename(nowtime,rndnum) txtname=htmlname&".txt" filez=cfolder(nowtime,pathname)&"\"&txtname '生成.txt 'response.Write(filez) 'response.End() set st=fs.createtextfile(filez,true) for i=1 to len(body) write_one=mid(body,i,1) st.write(write_one) next st.close set st=nothing if err.number<>0 then '有错误发生时! isok=0:err.clear:exit function end if 'filepath=cfolder(nowtime,pathname) 'filepath=filepath&txtname Set MyFile = fs.GetFile(filez) 'response.Write(len(filez)-4) 'response.Write( left(filez,(len(filez)-4))&".htm") 'response.End() MyFile.name=left(MyFile.name,len(MyFile.name)-4)&".htm" if err.number<>0 then '更改后缀名有错误时 '删除.txt文件 fs.delectfile(filepath) isok=0:err.clear:exit function end if set myfile=nothing 'fs.close set fs=nothing makehtml=isok end function %> 测试页面: <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> <!--#include file="../inc/makehtml.asp"--> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>无标题文档</title> </head>
<body> <% dim rndm,path,nows,body rndm=rndn() path="test" nows=now() body="abasdfsdfasdfadfsd" if makehtml(nows,body,path,rndm)=0 then response.Write("生成失败") else response.Write("生成成功") end if %> </body> </html> 我测试通过,有问题可以联系我!