|
建站常识 |
|
|
|
|
|
|
|
|
ASP模版与自动生成HTML文件代码。
2007/6/20
返回前页 |
|
SELECT CASE REQUEST("action") '先放到库中,再生成页面 '添加开始--------------------------------------------------------------------------------- CASE "add" title=request("title") content=request("content") moban=request("moban") class_id=request("class_id") class_name=request("class_name") class_big=request("class_big") zz=request("zz") from=request("from") up=request("up") pic=request("pic") picurl=request("images") addtime=now() hits=request("hits") fname=makefilename(addtime) addtime=now() if title="" and content="" then response.write " " else set rs=server.createobject("adodb.recordset") sql="select * from article where (id=null)" rs.open sql,conn,1,3 rs.addnew rs("title")=title rs("content")=content rs("moban_id")=moban rs("class_id")=class_id rs("class_name")=class_name rs("class_big")=class_big rs("pic")=pic rs("picurl")=picurl rs("addtime")=addtime rs("zz")=zz rs("from")=from rs("hits")=hits rs("up")=up rs.update
moban_id=rs("moban_id") title=rs("title") content=txt(rs("content")) addtime=rs("addtime") addtime=FormatDateTime(addtime,1) fileid=rs("id") fname=fname&FileType rs("fname")=fname rs("oktime")=addtime rs.update rs.close
生成页面程序开始 sql="select * from moban where id="&moban_id&" " 'moban是数字,是模版id rs.open sql,conn,1,1 okweb=rs("content") '替换模版中的相关字段 okweb=replace(okweb,"$nnso_title",title)'文章题目 okweb=replace(okweb,"$nnso_content",content)'文章内容 okweb=replace(okweb,"$nnso_addtime",addtime)'录入时间 okweb=replace(okweb,"$nnso_from",from)'文章出处 okweb=replace(okweb,"$nnso_class_big",class_big)'大类 okweb=replace(okweb,"$nnso_class_name",class_name)'小类名称 okweb=replace(okweb,"$nnso_path",class_id)'位置,路径 okweb=replace(okweb,"$nnso_zz",zz)'文章作者 okweb=replace(okweb,"$nnso_id",fileid)'评论时候的id '开始生成 Set fso = Server.CreateObject("Scripting.FileSystemObject") filePath=server.mappath(("../html/")&(class_id)) Set f = fso.CreateTextFile(filePath& "\" & fname) f.WriteLine okweb f.close '生成页面程序结束
'添加日志 ips=Request.ServerVariables("Remote_Addr") sj=now conn.Execute "INSERT INTO log(username,action,ip,sj) VALUES('文章添加','["&title&"]成功添加','"&ips&"','"&sj&"' )" end if rs.close set rs=nothing conn.close set conn=nothing response.redirect "article.asp?class_id="&class_id&"" '添加结束---------------------------------------------------------------------------------
'修改开始--------------------------------------------------------------------------------- CASE "mod" '第一步:删除目录下的文件 fileid=request("id") class_id=request("class_id") fname=request("fname") filePath=server.mappath(("../html/")&(class_id))& "\" &fname Set fso = CreateObject("Scripting.FileSystemObject") fso.DeleteFile(filepath) Set fso = nothing on error resume next '先删除目录下文件,再删除库中的记录,否则无法进行查询 title=request("title") content=request("content") moban=request("moban") class_id=request("class_id") class_name=request("class_name") class_big=request("class_big") zz=request("zz") from=request("from") up=request("up") pic=request("pic") picurl=request("images") hits=request("hits") if title="" and content="" then response.write " " else set rs=server.createobject("adodb.recordset") sql="select * from article where id="+fileid rs.open sql,conn,1,3 rs("title")=title rs("content")=content rs("moban_id")=moban rs("class_id")=class_id rs("class_name")=class_name rs("class_big")=class_big rs("pic")=pic rs("picurl")=picurl rs("zz")=zz rs("from")=from rs("hits")=hits rs("up")=up rs.update
moban_id=moban title=txt(rs("title")) content=txt(rs("content")) addtime=rs("addtime") addtime=FormatDateTime(addtime,1) fileid=rs("id") rs.close
'生成页面程序开始 sql="select * from moban where id="&moban_id&" " 'moban是数字,是模版id rs.open sql,conn,1,1 okweb=rs("content") '替换模版中的相关字段 okweb=replace(okweb,"$nnso_title",title)'文章题目 okweb=replace(okweb,"$nnso_content",content)'文章内容 okweb=replace(okweb,"$nnso_addtime",addtime)'录入时间 okweb=replace(okweb,"$nnso_from",from)'文章出处 okweb=replace(okweb,"$nnso_path",class_id)'位置,路径 okweb=replace(okweb,"$nnso_class_big",class_big)'大类 okweb=replace(okweb,"$nnso_class_name",class_name)'小类名称 okweb=replace(okweb,"$nnso_zz",zz)'文章作者 okweb=replace(okweb,"$nnso_id",fileid)'评论时候的id '开始生成 Set fso = Server.CreateObject("Scripting.FileSystemObject") filePath=server.mappath(("../html/")&(class_id)) Set f = fso.CreateTextFile(filePath& "\" & fname) f.WriteLine okweb f.close '添加日志 ips=Request.ServerVariables("Remote_Addr") sj=now conn.Execute "INSERT INTO log(username,action,ip,sj) VALUES('文章修改','"&fname&"-修改成功','"&ips&"','"&sj&"' )" end if rs.close set rs=nothing conn.close set conn=nothing response.redirect "article.asp?class_id="&class_id&""
'生成页面程序结束 '修改结束--------------------------------------------------------------------------------
'删除开始-------------------------------------------------------------------------------- CASE "del" articleid=request("id") class_id=request("class_id") set rs=server.createobject("adodb.recordset") sql="select id,class_id,fname from article where id="+articleid rs.open sql,conn,1,3 fname=rs("fname") class_id=rs("class_id") rs.close set rs=nothing
'删除目录下的文章 filePath=request.ServerVariables("APPL_PHYSICAL_PATH")&("html\")&(class_id)& "\" &fname Set fso = CreateObject("Scripting.FileSystemObject") fso.DeleteFile(filepath) Set fso = nothing '先删除目录下文件,再删除库中的记录,否则无法进行查询 conn.execute("delete from article where id="&articleid&"") '添加日志 ips=Request.ServerVariables("Remote_Addr") sj=now conn.Execute "INSERT INTO log(username,action,ip,sj) VALUES('文章删除','"&fname&"-成功删除','"&ips&"','"&sj&"' )" conn.close set conn=nothing '重定向返回 response.redirect "article.asp?class_id="&class_id&"" '删除结束--------------------------------------------------------------------------------
END SELECT |
|
|
|
|
广告也精彩 |
|
|
|