分享

写回答

发帖

[提问] 求助。。GODADDY.ASP生成HTM文件名问题。。。

GoDaddy GoDaddy 1482 人阅读 | 8 人回复

发表于 2010-7-1 14:53:01 | 显示全部楼层 |阅读模式

  1. <!--#include file="articleconn.asp"-->
  2. <%
  3. function changechr(str)
  4.     changechr=replace(replace(replace(replace(str,"<","&lt;"),">","&gt;"),chr(13),"
  5. ")," ","&nbsp;")
  6.     changechr=replace(replace(replace(replace(changechr,"[sayyes]","<img src="),"[b]","<b>"),"[red]","<font color=CC0000>"),"[big]","<font size=7>")
  7.     changechr=replace(replace(replace(replace(changechr,"[/sayyes]","></img>"),"[/b]","</b>"),"[/red]","</font>"),"[/big]","</font>")
  8. end function

  9. function makefilename(fname)
  10.   fname = now()
  11.   fname = replace(fname,"-","")
  12.   fname = replace(fname," ","")
  13.   fname = replace(fname,":","")
  14.   fname = replace(fname,"PM","")
  15.   fname = replace(fname,"AM","")
  16.   fname = replace(fname,"上午","")
  17.   fname = replace(fname,"下午","")
  18.   makefilename=fname & ".htm"
  19. end function
  20. %>

  21. <%
  22. IF not(Session("KEY")="super" or session("KEY")="check" or Session("KEY")="input") THEN
  23.         response.redirect "mymanage.asp"
  24.         response.end
  25. END IF

  26. if request.form("txttitle")="" then
  27. response.write "错误提示:请输入文章标题!"
  28. response.end
  29. end if
  30. if request.form("txtcontent")="" then
  31. response.write "错误提示:请未输入文章内容!"
  32. response.end
  33. end if
  34. dim title
  35. dim content
  36. dim sql
  37. dim rs
  38. dim articleid
  39. dim classid,Nclassid
  40. dim from

  41. title=request.form("txttitle")
  42. from=request.form("Nfrom")
  43. zznews=request.form("zznews")
  44. typeid=request.form("typeid")
  45. about=request.form("about")


  46. dim sql1
  47. dim rs1
  48. dim typename1
  49. sql1="select * from type where typeid="&typeid
  50. set rs1=server.createobject("adodb.recordset")
  51. rs1.open sql1,conn,1,1
  52. typename1=rs1("type")
  53. filepath=rs1("typename")

  54. if request.form("checkbox1")="1" then
  55. tjnews=1
  56. else
  57. tjnews=2
  58. end if

  59. if request.form("checkbox3")="1" then
  60. selectpic=1
  61. else
  62. selectpic=0
  63. end if


  64. if Session("KEY")="input" then
  65. shenghe=2
  66. else
  67. if request.form("checkbox2")="1" then
  68. shenghe=2
  69. else
  70. shenghe=1
  71. end if
  72. end if

  73. content=changechr(request.form("txtcontent"))
  74.         set rs = server.CreateObject("ADODB.RecordSet")
  75.                StrSql = "select E_Memo from Example where id="+request("Example")
  76.         set rs = conn.Execute (StrSql)
  77. fname = makefilename(now())

  78. dddd = year(now()) & "年" & month(now()) & "月" & day(now()) & "日" & hour(now())&":"&minute(now())
  79. pencat=rs("E_Memo")
  80. pencat=replace(pencat,"lx",typename1)
  81. pencat=replace(pencat,"Date",dddd)
  82. if from="" then
  83. pencat=replace(pencat,"From","醉心消息")
  84. else
  85. pencat=replace(pencat,"From",from)
  86. end if
  87. if zznews="" then
  88. pencat=replace(pencat,"Fname","醉心消息")
  89. else
  90. pencat=replace(pencat,"Fname",zznews)
  91. end if
  92. pencat=replace(pencat,"H_Title",title)
  93. pencat=replace(pencat,"H_Memo",content)
  94. pencat=replace(pencat,"labout",about)

  95. Set fso = Server.CreateObject("Scripting.FileSystemObject")
  96. Set fout = fso.CreateTextFile(server.mappath(filePath& "" & fname))
  97. fout.WriteLine pencat
  98. fout.close

  99. set rs=server.createobject("adodb.recordset")
  100. sql="select * from article where (newsid is null)"
  101. rs.open sql,conn,1,3
  102. rs.addnew
  103. rs("title")=title
  104. rs("path")=filepath
  105. rs("content")=content
  106. rs("Nfrom")=from
  107. rs("selectpic")=selectpic
  108. rs("typeid")=typeid
  109. rs("typename")=typename1
  110. rs("tjnews")=tjnews
  111. rs("shenghe")=shenghe
  112. rs("N_Fname")=fname
  113. rs("zznews")=zznews
  114. rs("about")=about
  115. rs.update

  116. articleid=rs("newsid")
  117. rs1.close
  118. set rs1=nothing
  119. rs.close
  120. set rs=nothing
  121. conn.close
  122. set conn=nothing
  123. %><head>
  124. </head>



  125. <div align="center">
  126.   <table border="0" cellspacing="1" width="50%" bgcolor="#000000" bordercolorlight="#11B1FF" bordercolordark="#F0F8FF" cellpadding="0">
  127.     <tr bgcolor="#000066">
  128.       <td width="100%" height="20">
  129.         <p align="center"><font color="#FFFFFF"><b>添加文章成功</b></font>
  130.       </td>
  131.     </tr>
  132.     <tr>
  133.       <td width="100%" bgcolor="#FFFFFF">
  134.         <p align="left">

  135.         其文件名为:<%=fname%>

  136.         文件标题为:<%response.write title%></p>
  137.     <p align="center">是否继续添加?

  138.          

  139.     <a href="myaddarticle.asp">
  140.     是</a>&nbsp;&nbsp; <a href="mymanage.asp">否</a>

  141.    

  142.     </p>
  143.         </td>
  144.     </tr>
  145.     </table>
  146. </div>
复制代码
这段ASP代码,是取文章当前发布时间作为生成HTM的。。
我想取文章ID做为生成HTM的文件名,请问该怎么改,文章ID函数是 newsid
这段代码在国内空间上是可以正常按时间生成文件的。但放到GODADDY上之后生成的文件就变成了文件名为:6/30/2010100640.htm这样的,多了目录路径。。
所以我想把它换成用文章ID作为文件名,但是我改了半天都不能生成。。
请教!

回答|共 8 个

add.c

发表于 2010-7-1 15:05:01 | 显示全部楼层

不会改  帮顶一次

xwbar

发表于 2010-7-1 15:07:36 | 显示全部楼层

高手帮帮忙
RAKSmart

xwbar

发表于 2010-7-1 15:32:34 | 显示全部楼层

:)

xwbar

发表于 2010-7-1 19:55:19 | 显示全部楼层

:) :)

sharesun

发表于 2010-7-1 20:12:08 | 显示全部楼层

人家是英文系统,日期时间的格式是 6/30/2010 这样的,而国内的中文系统格式是 2010-06-30,所以如果用日期生成文件名,必须先把“/”用replace替换成“-”,这样就不会生成那么多的路径了,所以如果我的想法没有错误的话,可以按如下修改一试:
function makefilename(fname)
  fname = now()


这里把 fname = now() 改成 fname = replace(now(),"/","-")


这样修改后,原先应该生成 2010-06-30.html 这样的形式,变成 06-30-2010.html 了,希望能帮到你。

[ 本帖最后由 sharesun 于 2010-7-1 08:14 PM 编辑 ]

xwbar

发表于 2010-7-2 00:01:18 | 显示全部楼层

谢谢6楼的,我这样改了后文件名是变成你说的这样了。。
但是我生成后就页面空白,源码里只有这段代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312"></HEAD>
<BODY></BODY></HTML>

xwbar

发表于 2010-7-2 00:03:45 | 显示全部楼层

目录有写权限

xwbar

发表于 2010-7-2 00:09:13 | 显示全部楼层

解决了

Set fout = fso.CreateTextFile(server.mappath(filePath& "\" & fname),true,UTF-8)
您需要登录后才可以回帖 登录 | 注册

本版积分规则