asp编程实例用文本+ASP打造新闻发布系统

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

//图片上传〈SCRIPTRUNAT=SERVERLANGUAGE=VBSCRIPT〉FunctionGetUpload(FormData)DimDataStart,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)SetFields=CreateObject(Scripting.Dictionary)WhilePosOpenBoundary〉0AndPosCloseBoundary〉0'name起始位置(name=xxxxx),加6是因为[name=]长度为6FieldNameStart=InStrB(PosOpenBoundary,FormData,str2bin(name=))+6FieldNameSize=InStrB(FieldNameStart,FormData,ChrB(34))-FieldNameStart'()的ASC值=34FormFieldName=bin2str(MidB(FormData,FieldNameStart,FieldNameSize))'filename起始位置(filename=xxxxx)FieldFileNameStart=InStrB(PosOpenBoundary,FormData,str2bin(filename=))+10IfFieldFileNameStart〈PosCloseBoundaryAndFieldFileNameStart〉PosopenBoundaryThenFieldFileNameSize=InStrB(FieldFileNameStart,FormData,ChrB(34))-FieldFileNameStart'()的ASC值=34FormFileName=bin2str(MidB(FormData,FieldFileNameStart,FieldFileNameSize))ElseFormFileName=EndIf'Content-Type起始位置(Content-Type:xxxxx)FieldFileCTStart=InStrB(PosOpenBoundary,FormData,str2bin(Content-Type:))+14IfFieldFileCTStart〈PosCloseBoundaryAndFieldFileCTStart〉PosOpenBoundaryThenFieldFileCTSize=InStrB(FieldFileCTStart,FormData,str2bin(VbCrLf&VbCrLf))-FieldFileCTStartFormFileCT=bin2str(MidB(FormData,FieldFileCTStart,FieldFileCTSize))ElseFormFileCT=EndIf'数据起始位置:2个CRLF开始DataStart=InStrB(PosOpenBoundary,FormData,str2bin(VbCrLf&VbCrLf))+4IfFormFileName〈〉Then'数据长度,减1是因为数据文件的存取字节数问题(可能是AppendChunk方法的问题):'由于字节数为奇数的图象存到数据库时会去掉最后一个字符导致图象不能正确显示,'字节数为偶数的数据文件就不会出现这个问题,因此必须保持字节数为偶数。DataSize=InStrB(DataStart,FormData,DivStr)-DataStart-1FormFieldData=MidB(FormData,DataStart,DataSize)Else'数据长度,减2是因为分隔标志串前有一个CRLFDataSize=InStrB(DataStart,FormData,DivStr)-DataStart-2FormFieldData=bin2str(MidB(FormData,DataStart,DataSize))EndIf'建立一个Dictionary集存储Form中各个Field的相关数据SetField=CreateUploadField()Field.Name=FormFieldNameField.FilePath=FormFileNameField.FileName=GetFileName(FormFileName)Field.ContentType=FormFileCTField.Length=LenB(FormFieldData)Field.Value=FormFieldDataFields.AddFormFieldName,FieldPosOpenBoundary=PosCloseBoundaryPosCloseBoundary=InStrB(PosOpenBoundary+1,FormData,DivStr)WendSetGetUpload=FieldsEndFunction'把二进制字符串转换成普通字符串函数Functionbin2str(binstr)Dimvarlen,clow,ccc,skipflag'中文字符Skip标志skipflag=0ccc=IfNotIsNull(binstr)Thenvarlen=LenB(binstr)Fori=1TovarlenIfskipflag=0Thenclow=MidB(binstr,i,1)'判断是否中文的字符IfAscB(clow)〉127Then'AscW会把二进制的中文双字节字符高位和低位反转,所以要先把中文的高低位反转ccc=ccc&Chr(AscW(MidB(binstr,i+1,1)&clow))skipflag=1Elseccc=ccc&Chr(AscB(clow))EndIfElseskipflag=0EndIfNextEndIfbin2str=cccEndFunction'把普通字符串转成二进制字符串函数Functionstr2bin(varstr)str2bin=Fori=1ToLen(varstr)varchar=mid(varstr,i,1)varasc=Asc(varchar)'asc对中文字符求出来的值可能为负数,'加上65536就可求出它的无符号数值'-1在机器内是用补码表示的0xffff,'其无符号值为65535,65535=-1+65536'其他负数依次类推。Ifvarasc〈0Thenvarasc=varasc+65535EndIf'对中文的处理:把双字节低位和高位分开Ifvarasc〉255Thenvarlow=Left(Hex(Asc(varchar)),2)varhigh=right(Hex(Asc(varchar)),2)str2bin=str2bin&chrB(&H&varlow)&chrB(&H&varhigh)Elsestr2bin=str2bin&chrB(AscB(varchar))EndIfNextEndFunction'取得文件名(去掉Path)FunctionGetFileName(FullPath)IfFullPath〈〉ThenFullPath=StrReverse(FullPath)FullPath=Left(FullPath,InStr(1,FullPath,\)-1)GetFileName=StrReverse(FullPath)ElseGetFileName=EndIfEndFunction〈/SCRIPT〉〈SCRIPTRUNAT=SERVERLANGUAGE=JSCRIPT〉functionCreateUploadField(){returnnewuf_Init()}functionuf_Init(){this.Name=nullthis.FileName=nullthis.FilePath=nullthis.ContentType=nullthis.Value=nullthis.Length=null}〈/SCRIPT〉//新闻添加〈!--#includefile=news_session.asp--〉〈html〉〈head〉〈metahttp-equiv=Content-Languagecontent=zh-cn〉〈metahttp-equiv=Content-Typecontent=text/html;charset=gb2312〉〈styletype=text/css〉.buttonface{BACKGROUND-COLOR:#0079F2;BORDER-BOTTOM:#3333331pxoutset;BORDER-LEFT:#3333331pxoutset;BORDER-RIGHT:#ffffff1pxoutset;BORDER-TOP:#ffffff1pxoutset;COLOR:#ffffff;FONT-SIZE:9pta{color:#000000;text-decoration:none}〈/style〉〈SCRIPTID=clientEventHandlersJSLANGUAGE=javascript〉〈!--functionclient_onblur(ii){server=eval(form1.server+ii)if(server.value==){client=eval(form1.client+ii)clientvalue=client.value+varlen=clientvalue.lengtha=clientvalue.lastIndexOf('\\')clientvalue=clientvalue.substring(a+1)//alert(clientvalue);server.value=clientvalue}}functionform1_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();returnfalse}}}//--〉〈/SCRIPT〉〈title〉新闻发布系统〈/title〉〈/head〉〈bodybgcolor=#EDF0F5topmargin=10marginheight=5leftmargin=4marginwidth=0〉〈formmethod=POSTaction=news_input.aspname=form1enctype=multipart/form-dataLANGUAGE=javascriptonsubmit=returnform1_onsubmit()〉〈divalign=left〉〈tableborder=1width=754height=404〉〈tralign=center〉〈tdwidth=754height=28colspan=3style=font-size:11pt〉〈strong〉新闻发布系统后台管理--新闻添加〈/strong〉〈/td〉〈/tr〉〈tr〉〈tdwidth=121height=16align=centerstyle=font-size:9pt〉新闻标题〈/td〉〈tdwidth=617height=16colspan=2〉〈inputtype=textname=news_titlesize=87〉〈/td〉〈/tr〉〈tr〉〈tdwidth=121height=165align=centerstyle=font-size:

1 / 30
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功