仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 337|回复: 7
打印 上一主题 下一主题

[学习教程] ASP网页设计ASP静态网页实例:表单多文件上传类

[复制链接]
若相依 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:21:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
楼上说交互性不好,太牵强了吧。在微软提供的一套框架中,利用asp做网站,开发效率高,使用人数少,减少不必要的开销。交互性是互动方式,是有开发人员决定的。静态|上传|网页<%
ClassUpload
PublicForm,Finished
PrivatebVBCrlf,bSeparate,formData,cFields,folderPath,itemCount,sErrors,sAuthor,sVersion
PrivateitemStart(),itemLength(),dataStart(),dataLength(),itemName(),itemData(),extenArr()
PrivateSubClass_Initialize
formData=Request.BinaryRead(Request.TotalBytes)
SetForm=Server.CreateObject("Scripting.Dictionary")
sAuthor="51JS.COM-ZMM"
sVersion="UploadClass1.0"
EndSub

PublicPropertyGetErrMessage
ErrMessage=sErrors
EndProperty

PublicPropertyGetAuthor
Author=sAuthor
EndProperty
PublicPropertyGetVersion
Version=sVersion
EndProperty
PublicPropertyLetCheckFields(byValsCheck)
cFields=sCheck
EndProperty
PublicPropertyLetFolder(byValsFolder)
folderPath=sFolder
EndProperty
PublicFunctionStart
Finished=False
bVBCrlf=StrToByte(vbCrlf&vbCrlf)
bSeparate=StrToByte("-----------------------------")
itemCount=0
sErrors=""
CallItemPosition
EndFunction
PrivateFunctionItemPosition
DimiStart,iLength:iStart=1
DoUntilInStrB(iStart,formData,bSeparate)=0
iStart=InStrB(iStart,formData,bSeparate)+LenB(bSeparate)+14
iLength=InStrB(iStart,formData,bSeparate)-iStart-2
IfAbs(iStart+2-LenB(formData))>2Then
ReDimPreserveitemStart(itemCount)
ReDimPreserveitemLength(itemCount)
itemStart(itemCount)=iStart
itemLength(itemCount)=iLength
itemCount=itemCount+1
EndIf
Loop
CallFillItemValue
EndFunction
PrivateFunctionFillItemValue
DimdataPart,bInfor
DimiStart:iStart=1
DimiCount:iCount=0
DimiCheck:iCheck=StrToByte("filename")
Fori=0ToitemCount-1
ReDimPreserveitemName(iCount)
ReDimPreserveitemData(iCount)
ReDimPreserveextenArr(iCount)
ReDimPreservedataStart(iCount)
ReDimPreservedataLength(iCount)
dataPart=MidB(formData,itemStart(i),itemLength(i))
iStart=InStrB(1,dataPart,ChrB(34))+1
iLength=InStrB(iStart,dataPart,ChrB(34))-iStart
itemName(iCount)=FormItemName(MidB(dataPart,iStart,iLength))
iStart=InStrB(1,dataPart,bVBCrlf)+4
iLength=LenB(dataPart)-iStart+1
IfInStrB(1,dataPart,iCheck)>0Then
bInfor=MidB(dataPart,1,iStart-5)
extenArr(iCount)=FileExtenName(bInfor)
IfMid(folderPath,Len(folderPath)-1)="/"Then
itemData(iCount)=folderPath&GetRndName(6)&extenArr(iCount)
Else
itemData(iCount)=folderPath&"/"&GetRndName(6)&extenArr(iCount)
EndIf
dataStart(iCount)=itemStart(i)+iStart-2
dataLength(iCount)=iLength
Else
extenArr(iCount)=""
itemData(iCount)=ByteToStr(MidB(dataPart,iStart,iLength))
dataStart(iCount)=""
dataLength(iCount)=""
EndIf
iCount=iCount+1
Next
CallSaveUpload
EndFunction
PrivateFunctionFormItemName(byValbName)
FormItemName=ByteToStr(bName)
EndFunction
PrivateFunctionFileExtenName(byValbInfor)
DimpStart,pLength,pContent,regEx
pStart=InStr(1,ByteToStr(bInfor),"filename="&Chr(34))+10
pLength=InStr(pStart,ByteToStr(bInfor),Chr(34))-pStart
pContent=Mid(ByteToStr(bInfor),pStart,pLength)
IfpContent=""Then
FileExtenName=""
Else
SetregEx=NewRegExp
regEx.Pattern="^.*(.[^.]*)$"
regEx.Global=False
regEx.IgnoreCase=True
FileExtenName=regEx.Replace(pContent,"$1")
SetregEx=Nothing
EndIf
EndFunction
PrivateFunctionGetRndName(byValsLen)
DimregEx,sTemp,arrFields,n:n=0
SetregEx=NewRegExp
regEx.Pattern="[^d]*"
regEx.Global=True
regEx.IgnoreCase=True
sTemp=regEx.Replace(Now,"")&"-"
SetregEx=Nothing
arrFields=Array("0","1","2","3","4","5","6","7","8","9",_
"a","b","c","d","e","f","g","h","i","j",_
"k","l","m","n","o","p","q","r","s","t",_
"u","v","w","x","y","z","A","B","C","D",_
"E","F","G","H","I","J","K","L","M","N",_
"O","P","Q","R","S","T","U","V","W","X",_
"Y","Z")
Randomize
DoWhilen<sLen
sTemp=sTemp&CStr(arrFields(61*Rnd))
n=n+1
Loop
GetRndName=sTemp
EndFunction
PrivateFunctionSaveUpload
DimisValidate
DimfilePath,oStreamGet,oStreamPut
isValidate=CheckFile
IfisValidateThen
Fori=0ToitemCount-1
If(dataStart(i)"")And(dataLength(i)"")Then
IfdataLength(i)=0Then
itemData(i)=""
Else
filePath=Server.MapPath(itemData(i))
IfCreateFolder("|",ParentFolder(filePath))Then
SetoStreamGet=Server.CreateObject("ADODB.Stream")
oStreamGet.Type=1
oStreamGet.Mode=3
oStreamGet.Open
oStreamGet.WriteformData
oStreamGet.Position=dataStart(i)
SetoStreamPut=Server.CreateObject("ADODB.Stream")
oStreamPut.Type=1
oStreamPut.Mode=3
oStreamPut.Open
oStreamPut.WriteoStreamGet.Read(dataLength(i))
oStreamPut.SaveToFile(filePath)
oStreamGet.Close
SetoStreamGet=Nothing
oStreamPut.Close
SetoStreamPut=Nothing
EndIf
EndIf
EndIf
Next
Finished=True
CallItemToColl
Else
Finished=False
EndIf
EndFunction
PrivateFunctionCheckFile
DimoBoolean:oBoolean=True
IfcFields=""Then
oBoolean=oBooleanAndTrue
Else
Fori=0ToitemCount-1
IfextenArr(i)""Then
IfInStr(1,Ucase(cFields),"|"&Ucase(Mid(extenArr(i),2))&"|")>0Then
oBoolean=oBooleanAndTrue
Else
sErrors=sErrors&"表单["&itemName(i)&"]的文件格局毛病!
"&_
"撑持的格局为:"&Replace(Mid(cFields,2,Len(cFields)-1),"|","")&"

"
oBoolean=oBooleanAndFalse
EndIf
EndIf
Next
EndIf
CheckFile=oBoolean
EndFunction
PrivateFunctionCreateFolder(byValsLine,byValsPath)
DimoFso
SetoFso=Server.CreateObject("Scripting.FileSystemObject")
IfNotoFso.FolderExists(sPath)Then
DimregEx
SetregEx=NewRegExp
regEx.Pattern="^(.*)([^]*)$"
regEx.Global=False
regEx.IgnoreCase=True
sLine=sLine&regEx.Replace(sPath,"$2")&"|"
sPath=regEx.Replace(sPath,"$1")
IfCreateFolder(sLine,sPath)ThenCreateFolder=True
SetregEx=Nothing
Else
IfsLine="|"Then
CreateFolder=True
Else
DimsTemp:sTemp=Mid(sLine,2,Len(sLine)-2)
IfInStrRev(sTemp,"|")=0Then
sLine="|"
sPath=sPath&""&sTemp
Else
DimFolder:Folder=Mid(sTemp,InStrRev(sTemp,"|")+1)
sLine="|"&Mid(sTemp,1,InStrRev(sTemp,"|")-1)&"|"
sPath=sPath&""&Folder
EndIf
oFso.CreateFoldersPath
IfCreateFolder(sLine,sPath)ThenCreateFolder=True
Endif
EndIf
SetoFso=Nothing
EndFunction
FunctionParentFolder(byValsPath)
DimregEx
SetregEx=NewRegExp
regEx.Pattern="^(.*)[^]*$"
regEx.Global=True
regEx.IgnoreCase=True
ParentFolder=regEx.Replace(sPath,"$1")
SetregEx=Nothing
EndFunction
PrivateFunctionStrToByte(byValsText)
Fori=1ToLen(sText)
StrToByte=StrToByte&ChrB(Asc(Mid(sText,i,1)))
Next
EndFunction
PrivateFunctionByteToStr(byValsByte)
DimoStream
SetoStream=Server.CreateObject("ADODB.Stream")
oStream.Type=2
oStream.Mode=3
oStream.Open
oStream.WriteTextsByte
oStream.Position=0
oStream.CharSet="gb2312"
oStream.Position=2
ByteToStr=oStream.ReadText
oStream.Close
SetoStream=Nothing
EndFunction
PrivateFunctionItemToColl
Fori=0ToitemCount-1
IfNotForm.Exists(itemName(i))Then
Form.AdditemName(i),itemData(i)
EndIf
Next
EndFunction
PrivateSubClass_Terminate
Form.RemoveAll
SetForm=Nothing
EndSub
EndClass
IfRequest.ServerVariables("REQUEST_METHOD")="POST"Then
Rem创建上传类实例
SetoUpload=NewUpload
Rem指定同意上传文件的范例
oUpload.CheckFields="|GIF|BMP|JPG|"
Rem指定上传文件所存储的绝对路径
oUpload.Folder="51JS.COM-ZMM/UploadFile"
Rem入手下手上传处置
oUpload.Start
IfoUpload.FinishedThen
Rem上传乐成,显现上传信息
DimsHtml:sHtml=""
sHtml=sHtml&"<center>"
sHtml=sHtml&"<divstyle=""width:600px;height:500px;font-size:10pt;border:1pxsolidhighlight;overflow:auto;""align=""left"">"
sHtml=sHtml&"<centerstyle=""font-size:15pt;color:red;"">上传表双数据</center><br>"
sHtml=sHtml&"题目:<br>"&oUpload.Form("P_title")&"<br><br><br>"
sHtml=sHtml&"范例:<br>"&oUpload.Form("P_assort")&"<br><br><br>"
sHtml=sHtml&"小图:<br>服务器端路径:<ahref="""&oUpload.Form("P_p_w_picpath_s")&"""target=""_blank"">"&oUpload.Form("P_p_w_picpath_s")&"</a><br><br><br><br>"
sHtml=sHtml&"年夜图:<br>服务器端路径:<ahref="""&oUpload.Form("P_p_w_picpath_b")&"""target=""_blank"">"&oUpload.Form("P_p_w_picpath_b")&"</a><br><imgsrc="""&oUpload.Form("P_p_w_picpath_b")&"""><br><br><br>"
sHtml=sHtml&"先容:<br>"&oUpload.Form("P_content")&"<br>"
sHtml=sHtml&"</div>"
sHtml=sHtml&"</center>"
Response.WritesHtml
Response.End
Else
Rem上传失利,显现毛病信息
CallShowMsg(oUpload.ErrMessage,Request.ServerVariables("SCRIPT_NAME"))
EndIf
Rem对话框提醒函数
FunctionShowMsg(byValsText,byValsTarget)
DimsScript:sScript=""
sScript=sScript&"<scriptlanguage=""javascript"">"&vbCrlf&_
"window.alert("&sText&");"&vbCrlf&_
"window.location.replace("&sTarget&");"&vbCrlf&_
"</script>"
Response.WritesScript
Response.End
EndFunction
EndIf
%>
<html>
<head>
<title>多文件、表单夹杂上传类</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<styletype="text/CSS">
body{
margin:0px;
border:0px;
font-size:10pt;
}
table{
border-collapse:collapse;
font-size:10pt;
}
td{
font-size:10pt;
}
</style>
<scriptlanguage="javascript">
functionformCheck(_form){
for(vari=0;i<_form.elements.length;i++){
if(_form.elements[i].value==){
window.alert(请将表单填写完全,提交失利!);
returnfalse;
}
}
returntrue;
}
</script>
</head>
<body>
<br><br>
<formaction="<%=Request.ServerVariables("SCRIPT_NAME")%>"method="post"enctype="multipart/form-data">
<tablewidth="400"align="center"cellpadding="2"cellspacing="0"border="1"rules="box">
<trheight="26">
<tdcolspan="2"align="center"style="font:12pt;color:red;">上传功效测试<br><br></td>
</tr>
<trvalign="top">
<tdheight="30"style="padding-top:3px;">题目:</td>
<td><inputtype="text"name="P_title"size="20"autocomplete="off"></td>
</tr>
<trvalign="top">
<tdheight="30"style="padding-top:3px;">范例:</td>
<td>
<selectname="P_assort">
<optionvalue="电子">电子</option>
<optionvalue="医疗">医疗</option>
</select>
</td>
</tr>
<trvalign="top">
<tdheight="30"style="padding-top:3px;">小图:</td>
<td><inputtype="file"name="P_p_w_picpath_s"oncontextmenu="returnfalse;"onpaste="returnfalse;"ondragenter="returnfalse;"></td>
</tr>
<trvalign="top">
<tdheight="30"style="padding-top:3px;">中图:</td>
<td><inputtype="file"name="P_p_w_picpath_m"oncontextmenu="returnfalse;"onpaste="returnfalse;"ondragenter="returnfalse;"></td>
</tr>
<trvalign="top">
<tdheight="30"style="padding-top:3px;">年夜图:</td>
<td><inputtype="file"name="P_p_w_picpath_b"oncontextmenu="returnfalse;"onpaste="returnfalse;"ondragenter="returnfalse;"></td>
</tr>
<tr>
<tdheight="30"colspan="2"style="padding-top:3px;">先容:</td>
</tr>
<tr>
<tdheight="30"colspan="2"valign="top">
<textareaname="P_content"cols="50"rows="5"></textarea>
</td>
</tr>
<tr>
<tdcolspan="2"valign="top"align="center">
<br><inputtype="submit"value="提交"><inputtype="reset"value="重置">
<br><br>
</td>
</tr>
</table>
</form>
</body>
</html>
无法实现跨操作系统的应用。当然这也是微软的理由之一,只有这样才能发挥ASP最佳的能力。可是我却认为正是Windows限制了ASP,ASP的概念本就是为一个能让系统运行于一个大的多样化环境而设计的;
灵魂腐蚀 该用户已被删除
沙发
发表于 2015-1-19 09:26:23 | 只看该作者
掌握asp的特性而且一定要知道为什么。
金色的骷髅 该用户已被删除
板凳
发表于 2015-1-25 11:42:30 | 只看该作者
如何学好ASP,以前也有人问过,把回答给你转过来看看能否对你有帮助:
愤怒的大鸟 该用户已被删除
地板
发表于 2015-2-2 21:59:26 | 只看该作者
代码的可重用性差:由于是面向结构的编程方式,并且混合html,所以可能页面原型修改一点,整个程序都需要修改,更别提代码重用了。
若天明 该用户已被删除
5#
发表于 2015-2-25 06:49:49 | 只看该作者
兴趣爱好,那么你无须学编程,申请一个域名和空间,在网上下载一些免费开源的CMS系统,你不用改代码,只须熟悉它们的后台操作,像office一样简单方便,很快就能建一个站点,很多站长都是这样做的
飘飘悠悠 该用户已被删除
6#
发表于 2015-3-7 17:32:11 | 只看该作者
代码逻辑混乱,难于管理:由于ASP是脚本语言混合html编程,所以你很难看清代码的逻辑关系,并且随着程序的复杂性增加,使得代码的管理十分困难,甚至超出一个程序员所能达到的管理能力,从而造成出错或这样那样的问题。
乐观 该用户已被删除
7#
发表于 2015-3-15 10:02:53 | 只看该作者
尽管MS自己讲C#内核中更多的象VC,但实际上我还是认为它和Java更象一些吧。首先它是面向对象的编程语言,而不是一种脚本,所以它具有面向对象编程语言的一切特性,比如封装性、继承性、多态性等等,这就解决了刚才谈到的ASP的那些弱点。
谁可相欹 该用户已被删除
8#
发表于 2015-3-22 00:10:32 | 只看该作者
虽然ASP也有很多网络教程。但是这些都不系统。都是半路出家,只是从一个例子告诉你怎么用。不会深入讨论,更不会将没有出现在例子里的方法都一一列举出来。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-12-25 01:46

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表