<!–#include file="news_session.asp"–>
<html>
<head>
<meta http-equiv="content-language" content="zh-cn">
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style type="text/css">
.buttonface {
background-color: #0079f2; border-bottom: #333333 1px outset; border-left: #333333 1px outset; border-right: #ffffff 1px outset; border-top: #ffffff 1px outset; color: #ffffff; font-size: 9pta { color: #000000; text-decoration: none}
</style>
<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>
<title>新闻发布系统</title>
</head>
<body bgcolor=#edf0f5 topmargin=10 marginheight=5 leftmargin=4 marginwidth=0>
<form method="post" action="news_input.asp" name="form1" enctype="multipart/form-data" language=javascript onsubmit="return form1_onsubmit()">
<div align="left">
<table border="1" width="754" height="404">
<tr align="center">
<td width="754" height="28" colspan="3" style="font-size:11pt"><strong>新闻发布系统后台管理–新闻添加</strong></td>
</tr>
<tr>
<td width="121" height="16" align="center" style="font-size:9pt">新闻标题</td>
<td width="617" height="16" colspan="2">
<input type="text" name="news_title" size="87"></td>
</tr>
<tr>
<td width="121" height="165" align="center" style="font-size:9pt">新闻内容</td>
<td width="617" height="165" colspan="2"><textarea rows="11" name="news_content" cols="85"></textarea></td>
</tr>
<tr>
<td width="121" height="21" align="center" style="font-size:9pt">新闻来源</td>
<td width="617" height="21" colspan="2">
<input type="text" name="news_src" size="87"></td>
</tr>
<tr>
<td width="121" height="20" align="center" style="font-size:9pt" >图片上传</td>
<td width="617" height="20" colspan="2">
<input type="file" name="client1" size="20" readonly language=javascript onblur="return client_onblur(1)" >
<span style="font-size:9pt"></span> <input type="hidden" name="server1"> <input type="hidden" value="mysession" name="mysession"> </td>
</tr>
</table>
</div>
<p>
<input type="submit" value="递交" name="b1" class="buttonface"> <input type="reset" value="全部重写" name="b2" 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_admin1.asp" name="b2" style="font-size:10pt;color:#000000;" class="buttonface"></p>
</form>
</body>
</html>
###################
news_input.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 news_title,news_content,news_src,mysession
mysession=fields("mysession").value
if len(mysession)=0 then
response.write "非法登陆或超时请重新登陆"
response.end
end if
news_title=fields("news_title").value
news_title=replace(news_title,"|","|")
news_content=fields("news_content").value
news_src=fields("news_src").value
news_src=replace(news_src,"|","|")
if len(news_title)=0 then%>
<script>
alert("出错!新闻标题不能为空");
history.go(-1);
//window.location="news_add.asp";
</script>
<%response.end
end if
if len(news_content)=0 then%>
<script>
alert("出错!新闻内容不能为空");
history.go(-1);
</script>
<%end if
if len(news_src)=0 then%>
<script>
alert("出错!新闻来源不能为空");
history.go(-1);
</script>
<%response.end
end if
dim varchar
varchar=right(fields("server1").value,3)
if len(varchar)<>0 then
if varchar<>"gif" and varchar<>"jpg" then
%>
<script>
alert("出错!不能上传该图片类型");
history.go(-1);
</script>
<% response.end
else
end if
end if
###########将图片写入文件夹
set file_o=server.createobject("scripting.filesystemobject")
##########当前时间做图片名
dim newname,mytime,newfile,filename,id,image
endname=right(fields("server1").value,4)
mytime=now()
id=year(mytime)&month(mytime)&day(mytime)&hour(mytime)&minute(mytime)&second(mytime)
imageid=id&endname
#############写入图片
newfile="client1"
filename=fields("server1").value
if fields(newfile).filename<>"" then
file_name=server.mappath("./images/"&imageid&"")
set outstream=file_o.createtextfile(file_name,true,false)
binstr=fields(newfile).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_o.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
###################################################################################### 把新闻数据结构写入newslist文件
dim mappath,mytext,myfso,contenttext,news_addtime,news_point
news_point=1
news_addtime=mytime
set myfso=createobject("scripting.filesystemobject")
mappath=server.mappath("./")
set mytext=myfso.opentextfile(mappath&"\new_list.asp",8,-1)
dim mytext2
if len(varchar)<>0 then
mytext2=trim(id&","&news_title&","&id&".txt"&","&news_src&","&news_point&","&news_addtime&","&imageid&"|")
else
mytext2=trim(id&","&news_title&","&id&".txt"&","&news_src&","&news_point&","&news_addtime&"|")
end if
mytext.writeline(mytext2)
mytext.close
##############把新闻内容写入相应的文件中
set contenttext=myfso.opentextfile(mappath&"\news_content\"&id&".txt",8,-1)
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
############################################################################
contenttext.write htmlencode2(news_content)
contenttext.close
set myfso=nothing
%>
<script>
alert("发布成功");
window.location="news_add.asp";
</script>
