欢迎光临
我们一直在努力

用文本+ASP打造新闻发布系统(五)新闻修改

建站超值云服务器,限时71元/月

‘#######news_update.asp

<!–#include file="news_session.asp"–>

<script id=clienteventhandlersjs language=javascript>

<!–

function client_onblur(ii) {

server=eval("form1.server"+ii)

if(server.value==""){

client=eval("form1.client"+ii)

clientvalue=client.value+""

varlen=clientvalue.length

a=clientvalue.lastindexof(\\)

clientvalue=clientvalue.substring(a+1)

//alert(clientvalue);

server.value=clientvalue

}

}

function form1_onsubmit() {

for(i=1;i<1;i++){

client=eval("form1.client"+i)

server=eval("form1.server"+i)

if(client.value!="" && server.value==""){alert("上传后的文件名不能空!");server.focus();return false}

}

}

//–>

</script>

<% dim myid

myid=request.querystring ("id")

if len(myid)=0 then

response.write "没有该新闻"

response.end

end if

dim myfso,myread,mytext,newscontent

#######打开对应的新闻内容文件,并读取用变量存储

set myfso=createobject("scripting.filesystemobject")

if myfso.fileexists (server.mappath("./news_content/"&myid&".txt")) then

set myread=myfso.opentextfile(server.mappath("./news_content/"&myid&".txt"),1,0)

newscontent=myread.readall

myread.close

newscontent=replace(newscontent,"<br>",chr(13))

newscontent=replace(newscontent," "," ")

newscontent=replace(newscontent," ",chr(32))

newscontent=replace(newscontent," ",chr(34))

else

response.write "该新闻已被删除"

response.end

end if

dim mytext2,myread2 #######打开新闻列表文件

set myread2=myfso.opentextfile(server.mappath("./new_list.asp"),1,0)

if myread2.atendofstream then

response.write "没有新闻内容"

response.end

end if

mytext2=myread2.readall

dim listarray

listarray=split(mytext2,"|") #########读取记录并以#分割成listarray数组

dim count,sf,i,title,src

count=ubound(listarray)

for i=0 to count ###########根据id找到该新闻并用变量存储给新闻的标题

sf=split(listarray(i),",")

if right(sf(0),7)=right(myid,7) then

title=sf(1)

src=sf(3)

exit for

end if

next

%>

<head>

<style>

td {font-size:9pt}

input.buttonface {

background-color: #0079f2; border-bottom: #333333 1px outset; border-left: #333333 1px outset; border-right: #ffffff 1px outset; border-top: #ffffff 1px inset; color: black; font-size: 9pta { color: #000000; text-decoration: none}

.text {font-size:11pt}

input.buttonface2 {

background-color: #edf0f5; color: black; font-size: 9pta { color: #000000; text-decoration: none}

a:hover { color: white; text-decoration: underline overline; background: #007ebb}

.text {font-size:11pt}

</style>

</head>

<body bgcolor=#edf0f5 topmargin=10 marginheight=5 leftmargin=4 marginwidth=0>

<form method="post" action="news_updateing.asp" name="form1" enctype="multipart/form-data" onsubmit="return form1_onsubmit()">

<div align="left">

<table border="1" width="752" height="240" cellspacing="0" cellpadding="0">

<tr>

<td colspan="2" height="12" align="center" width="800" style="font-size:12pt"><strong>新闻发布系统后台管理–新闻修改</strong></td>

</tr>

<tr>

<td width="119" height="12" style="font-size:9pt">新闻标题</td>

<td width="675" height="12">

<input type="text" name="newtitle" size="94" value="<%=title%>" class="buttonface2 ">

</td>

</tr>

<tr>

<td width="119" height="213" style="font-size:9pt">

新<br>

闻<br>

内<br>

容</td>

<td width="675" height="213">

<textarea rows="14" name="newcontent" cols="93" style="background-color: #edf0f5"><%=newscontent%></textarea>

<br>

</td>

</tr>

<tr>

<td width="119" height="4" style="font-size:9pt">新闻来源</td>

<td width="675" height="4">

<input type=text name="newssrc" value="<%=src%>" size="93" class="buttonface2 ">

</td>

</tr>

<tr>

<td width="119" height="5" style="font-size:9pt">图片上传</td>

<td width="675" height="5"> <input type="file" name="client1" size="20" readonly language=javascript onblur="return client_onblur(1)" ></td>

</tr>

</table>

</div>

<p>

<input type="submit" value="确认" name="b1" style="font-size: 10pt; color: #000000; " class="buttonface">

<input type="reset" value="全部重写" name="b2" style="font-size:10pt;color:#000000;" class="buttonface">

<input type="button" value="帐号修改" onclick="location.href=admin/news_chadmin.asp" name="b2" style="font-size:10pt;color:#000000;" class="buttonface">

<input type="button" value="新闻添加" onclick="location.href=news_add.asp" name="b2" style="font-size:10pt;color:#000000;" class="buttonface"></p>

<input type=hidden name="myid" value="<%=myid%>">

<input type="hidden" name="server1">

<input type="hidden" name="mysession" value="mysession">

</form>

##########

news_updating.asp

<!–#include file="news_session.asp"–>

<!–#include file="upload.inc"–>

<%

fields("xxx").name 取得form中xxx(form object)的名字

fields("xxx").filepath 如果是file object 取得文件的完整路径

fields("xxx").filename 如果是file object 取得文件名

fields("xxx").contenttype 如果是file object 取得文件的类型

fields("xxx").length 取得form中xxx(form object)的数据长度

fields("xxx").value 取得form中xxx(form object)的数据内容

dim formdata,formsize,gnote,bnote,notes,binlen,binstr

formsize=request.totalbytes

formdata=request.binaryread(formsize)

set fields = getupload(formdata)

############判断输入错误

dim mytitle,content,src,id,mysession

mysession=fields("newtitle").value

if len(mysession)=0 then

response.write "非法登陆或超时间,请重新登陆"

response.end

end if

mytitle=fields("newtitle").value

mytitle=replace(mytitle,"|","|")

mytitle=replace(mytitle,"<br>","")

content=fields("newcontent").value

src=fields("newssrc").value

src=replace(src,"|","|")

src=replace(src,"<br>","")

id=trim(right(fields("myid").value,12))

if len(mytitle)=0 then

response.write "<script>"

response.write "alert(出错!新闻标题不能为空!);"

response.write"location.href=history.go(-1);"

response.write "</script>"

end if

if len(content)=0 then

response.write "<script>"

response.write "alert(出错!新闻内容不能为空!);"

response.write"location.href=history.go(-1);"

response.write "</script>"

end if

if len(src)=0 then

response.write "<script>"

response.write "alert(出错!新闻来源不能为空!);"

response.write"location.href=history.go(-1);"

response.write "</script>"

end if

############################################################################################图片更该功能的实现

newfile="client1"

if fields(newfile).filename<>"" then

set file_0=server.createobject("scripting.filesystemobject")

dim contextname

contextname=right(fields("client1").filename,4)

imageid=id&contextname

if contextname<>".gif" and contextname<>".jpg" then #########判断上传文件格式

response.write "<script>"

response.write "alert(出错!上传文件格式不对 只能为jpg/gif图片格式!);"

response.write"location.href=history.go(-1);"

response.write "</script>"

end if

file_name=server.mappath("./images/"&imageid&"")

#####################################如果原来有图片文件主名为id的则删除该图片

if file_0.fileexists(server.mappath ("./images/"&id&".gif")) then

set f3 = file_0.getfile(server.mappath ("./images/"&id&".gif"))

f3.delete

end if

if file_0.fileexists(server.mappath ("./images/"&id&".jpg")) then

set f3 = file_0.getfile(server.mappath ("./images/"&id&".jpg"))

f3.delete

end if

########################################写入图片

set outstream=file_0.opentextfile(file_name,8,-1)

binstr=fields("client1").value

binlen=1

varlen=lenb(binstr)

for i=1 to varlen

clow = midb(binstr,i,1)

if ascb(clow) = 255 then

outstream.write chr(255)

binlen=binlen+1

if (i mod 2)=0 then

notes=gnote

exit for

end if

elseif ascb(clow) > 128 then

clow1=midb(binstr,i+1,1)

if ascb(clow1) <64 or ascb(clow1) =127 or ascb(clow1) = 255 then

binlen=binlen+1

if (binlen mod 2)=0 then

binlen=binlen+1

outstream.write chr(ascw(chrb(128)&clow))

end if

notes=bnote

exit for

else

outstream.write chr(ascw(clow1&clow))

binlen=binlen+2

i=i+1

if (i mod 2)=0 then

notes=gnote

exit for

end if

end if

else

outstream.write chr(ascb(clow))

binlen=binlen+1

if (i mod 2)=0 then

notes=gnote

exit for

end if

end if

next

outstream.close

set outstream=file_0.opentextfile(file_name,8,false,-1)

outstream.write midb(fields(newfile).value,binlen)

outstream.close

if notes=bnote then notes=notes&(binlen-1)&"字节处。"

end if

#######################################################################################################

dim myfso,mywrite #######修改新闻详细内容

set myfso=createobject("scripting.filesystemobject")

if myfso.fileexists(server.mappath("./news_content/"&id&".txt")) then

myfso.deletefile (server.mappath("./news_content/"&id&".txt"))

end if

set mywrite=myfso.createtextfile(server.mappath("./news_content/"&id&".txt"),-1,0)

mywrite.write content

dim mytext2,myread2 #########修改新闻的标题来源

set myread2=myfso.opentextfile(server.mappath("./new_list.asp"),1,0)

mytext2=myread2.readall

dim listarray,i,h,count,sf

listarray=split(mytext2,"|") #########读取记录并以#分割成listarray数组

count=ubound(listarray)

for i=0 to count ###########根据id找到该新闻记录

sf=split(listarray(i),",")

if right(sf(0),7)=right(id,7) then

sf(1)=mytitle

sf(3)=src

#######为6说明上传了图片,存储新的数组实现查看记录点击次数加1

if ubound(sf)=6 then

if fields(newfile).filename<>"" then

sf(6)=imageid

end if

listarray(i)=sf(0)&","&sf(1)&","&sf(2)&","&sf(3)&","&sf(4)&","&sf(5)&","&sf(6)

else

listarray(i)=sf(0)&","&sf(1)&","&sf(2)&","&sf(3)&","&sf(4)&","&sf(5)

end if

##################

exit for

end if

next

function htmlencode2(str) #############字符处理函数

dim result

dim l

l=len(str)

result=""

dim i

for i = 1 to l

select case mid(str,i,1)

case chr(34)

result=result+""

case "&"

result=result+"&"

case chr(13)

result=result+"<br>"

case " "

result=result+" "

case chr(9)

result=result+" "

case chr(32)

if i+1<=l and i-1>0 then

if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then

result=result+" "

else

result=result+" "

end if

else

result=result+" "

end if

case else

result=result+mid(str,i,1)

end select

next

htmlencode2=result

end function

##########################

dim k,mytext,mappath

mappath=server.mappath("./")

set mytext=myfso.createtextfile(mappath&"\new_list.asp",-1,0)

for i=0 to ubound(listarray) ##########把所有数据重新写入文件

if i=ubound(listarray) then

mytext.write htmlencode2(listarray(i))

else

mytext.write htmlencode2(listarray(i)&"|")

end if

next

%>

<script language="javascript">

alert("更改成功");

window.location=("news_admin1.asp");

</script>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用文本+ASP打造新闻发布系统(五)新闻修改
分享到: 更多 (0)

相关推荐

  • 暂无文章