7.6 用文本+ASP打造新闻发布系统

2016-02-19 14:04 7 1 收藏

今天图老师小编给大家精心推荐个7.6 用文本+ASP打造新闻发布系统教程,一起来看看过程究竟如何进行吧!喜欢还请点个赞哦~

【 tulaoshi.com - Web开发 】

//图片上传
〈SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT〉
Function GetUpload(FormData)
Dim DataStart,DivStr,DivLen,DataSize,FormFieldData
'分隔标志串(+CRLF)
DivStr = LeftB(FormData,InStrB(FormData,str2bin(VbCrLf)) + 1)
'分隔标志串长度
DivLen = LenB(DivStr)
PosOpenBoundary = InStrB(FormData,DivStr)
PosCloseBoundary = InStrB(PosOpenBoundary + 1,FormData,DivStr)
Set Fields = CreateObject("Scripting.Dictionary")

While PosOpenBoundary 〉 0 And PosCloseBoundary 〉 0
'name起始位置(name="xxxxx"),加6是因为[name="]长度为6
FieldNameStart = InStrB(PosOpenBoundary,FormData,str2bin("name=")) + 6
FieldNameSize = InStrB(FieldNameStart,FormData,ChrB(34)) - FieldNameStart '(")的ASC值=34
FormFieldName = bin2str(MidB(FormData,FieldNameStart,FieldNameSize))

'filename起始位置(filename="xxxxx")
FieldFileNameStart = InStrB(PosOpenBoundary,FormData,str2bin("filename=")) + 10
If FieldFileNameStart 〈 PosCloseBoundary And FieldFileNameStart 〉 PosopenBoundary Then
FieldFileNameSize = InStrB(FieldFileNameStart,FormData,ChrB(34)) - FieldFileNameStart '(")的ASC值=34
FormFileName = bin2str(MidB(FormData,FieldFileNameStart,FieldFileNameSize))
Else
FormFileName = ""
End If

'Content-Type起始位置(Content-Type: xxxxx)
FieldFileCTStart = InStrB(PosOpenBoundary,FormData,str2bin("Content-Type:")) + 14
If FieldFileCTStart 〈 PosCloseBoundary And FieldFileCTStart 〉 PosOpenBoundary Then
FieldFileCTSize = InStrB(FieldFileCTStart,FormData,str2bin(VbCrLf & VbCrLf)) - FieldFileCTStart
FormFileCT = bin2str(MidB(FormData,FieldFileCTStart,FieldFileCTSize))
Else
FormFileCT = ""
End If

'数据起始位置:2个CRLF开始
DataStart = InStrB(PosOpenBoundary,FormData,str2bin(VbCrLf & VbCrLf)) + 4
If FormFileName 〈〉 "" Then
'数据长度,减1是因为数据文件的存取字节数问题(可能是AppendChunk方法的问题):
'由于字节数为奇数的图象存到数据库时会去掉最后一个字符导致图象不能正确显示,
'字节数为偶数的数据文件就不会出现这个问题,因此必须保持字节数为偶数。
DataSize = InStrB(DataStart,FormData,DivStr) - DataStart - 1
FormFieldData = MidB(FormData,DataStart,DataSize)
Else
'数据长度,减2是因为分隔标志串前有一个CRLF
DataSize = InStrB(DataStart,FormData,DivStr) - DataStart - 2
FormFieldData = bin2str(MidB(FormData,DataStart,DataSize))
End If
'建立一个Dictionary集存储Form中各个Field的相关数据
Set Field = CreateUploadField()
Field.Name = FormFieldName
Field.FilePath = FormFileName
Field.FileName = GetFileName(FormFileName)
Field.ContentType = FormFileCT
Field.Length = LenB(FormFieldData)
Field.Value = FormFieldData

Fields.Add FormFieldName, Field

PosOpenBoundary

ZE: 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"〉新闻t; 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&",

array
for i=0 to recordcount-1 '########把每一条记录组成一个数组
j=split(listarray(i),",")
if ubound(j)=6 then
b(i)="〈SPAN style='COLOR: #ffbd00; FONT-SIZE: 7px'〉〈li〉〈/SPAN〉〈span style='font-size:10pt'〉〈a href='news_view.asp?id=" & j(0) & "' target=blank〉" & j(1) & "(图)〈/a〉 点击:" & j(4)&"次 最后发布时间:"&j(5)&"〈/span〉"
else
b(i)="〈SPAN style='COLOR: #ffbd00; FONT-SIZE: 7px'〉〈li〉〈/SPAN〉〈span style='font-size:10pt'〉〈a href='news_view.asp?id=" & j(0) & "' target=blank〉" & j(1) & "〈/a〉 点击:" & j(4)&"次 最后发布时间:"&j(5)&"〈/span〉"
end if
next

'########把记录反排序存储在新的数组实现按时间反排序
dim c(100)
n=0
for i=recordcount to 0 step -1
c(n)=b(i)
n=n+1
next

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)


dim currentrecord
currentrecord=pagesize*(topage-1)+1 '#########显示每一页
for k=1 to pagesize
if len(c(currentrecord))=0 then
exit for
end if
Response.Write c(currentrecord)&"〈br〉"
currentrecord=currentrecord+1
next
Response.Write "〈body bgcolor=#EDF0F5 topmargin=10 marginheight=5 leftmargin=4 marginwidth=0〉"
for m=1 to pagenum
response.write "〈span style=font-size:10pt〉〈a href=news_list.asp?topage="&m&"〉"&m&"〈/a〉〈/span〉 "
next

end if%
//新闻删除
〈!--#include file="news_session.asp"--〉
〈%
dim id
id=Request.QueryString ("id")
dim myfso
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

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)

dim mytext2,myread2
set myread2=myfso.opentextfile(server.mappath("./new_list.asp"),1,0)
if myread2.atendofstream then
Response.Write "没有新闻内容"
myread2.close
Response.End
end if
mytext2=myread2.readall
myread2.close
dim listarray,i,h,count,sf,title
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
dim thisid
thisid=i

'#######为6说明上传了图片,删除新闻图片和该列表记录
if ubound(sf)=6 then
myfso.deletefile(server.MapPath ("./images/"&sf(6)))
end if
exit for
end if
next

dim mytext,mappath
mappath=server.mappath(".

),7)=right(myid,7) then
title=sf(1)
src=sf(3)
sf(4)=sf(4)+1

'#######为6说明上传了图片,存储为新的数组
if ubound(sf)=6 then
listarray(i)=sf(0)&","&sf(1)&","&sf(2)&","&sf(3)&","&sf(4)&","&sf(5)&","&sf(6)
dim mypic
mypic=sf(6)
else
listarray(i)=sf(0)&","&sf(1)&","&sf(2)&","&sf(3)&","&sf(4)&","&sf(5)
end if
'##################
exit for
end if
next

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 listarray(i)
else
mytext.write listarray(i)&"|"
end if
next
Response.Write "〈body bgcolor=#EDF0F5 topmargin=10 marginheight=5 leftmargin=4 marginwidth=0〉"
Response.Write"〈div align=center style=font-size:13pt〉〈strong〉"&title&"〈/strong〉〈span〉〈/div〉〈br〉"
Response.Write "〈hr size=1〉"
if len(mypic)〈〉0 then
Response.write "〈center〉〈img src='./images/"&mypic&"'〉〈/center〉"
end if
Response.Write "〈span style=font-size:10pt〉"&htmlencode2(mytext1)&"〈/span〉"
Response.Write "〈br〉〈div align=right style='font-size:9pt'〉新闻

来源:http://www.tulaoshi.com/n/20160219/1606096.html

延伸阅读
标签: ASP
  通过定制这段代码,就能制作出符合您要求的网页显示格式。    添加,删除,显示都讲解完了,最后一项,就是把新闻的详细内容显示出来。    当用户点击新闻标题,就打开disp.asp文件,同时使用GET这种方式来把参数传 递过去,我们看看disp.asp的文件内容       《% @lan...
标签: ASP
  (三)把新闻代码插入你的页面    最好的新闻发布,当然是为网站本身定做的,那样才能与主页风格一致,但如此 一来,新闻发布系统有缺乏了通用性了,不能移值到别的网站上使用,有得必有失, 在这个基础上关键是找一个平行点。综合来考滤,最好的做法是与页面分离,那样就 可以不影响网页的外观,而也能达到很好的效...
标签: ASP
  程序处理完毕后,重新导向delete.asp这个asp文件,用以刷新新闻数据库内的显 示,那么每提交一条新闻资料,我们马上可以看见执行的结果是否成功了。    以下是delete.asp的文件内容。    《% @language="vbscript" %》    《%    response.buffer=true &nb...
标签: ASP
  更新每天新闻内容,对webmaster们来说是一件很头痛的事,首先,收集了大量 的新闻资料后,还必须制作大量的网页,每天大大小小的国际新闻,国内新闻,IT 新闻,可真够你累的。最致命的一点,这些松散的新闻是管理不了的,不能查询,不 能在线动态删改,新闻讲求时效性,当你作好网页然后上传到服务器上的时侯,恐怕 别人已早你一步,...
标签: ASP
  (一)构建新闻数据库    分析一下构成每条新闻的元素,主要由新闻标题,新闻内容,图片地址,连接地 址,新闻的发布时间组成。而在构建数据库的时候。考虑到处理需要,必需加上新闻 的ID号,以便识别。再者的话,可以加上点击统计,以便了解读者感性趣的内容。 access数据库是一个非常适合于开发阶段使用的过度时...

经验教程

196

收藏

56
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部