|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
asp可以使用微软的activeX使得网页功能无比强大,不过安全性也较差,而且是基于的windows服务器,所以性能稳定性也一般程序|上传|上传图片|无组件 起首,图片在页面中能查找选择。计划表单页面index.asp和上传选择页upload.asp,upload.asp在index.asp中以iframe包括。
其次,所选图片应能上传到某文件夹。创建一文件夹uploadimg
最初,传上往的图片应怎样援用?很明显,接纳UBB当即显现。upload.asp的指向工具upfile.asp具有写进UBB标签的功效。
无组件上传调试文件夹
--index.asp
--upload.asp
--upfile.asp
--uploadimg文件夹
图片上传接纳稻喷鼻老农的无组件上传。以是upload.inc文件必不成少。
1,upload.inc
<SCRIPTRUNAT=SERVERLANGUAGE=VBSCRIPT>
dimupfile_5xSoft_Stream
Classupload_5xSoft
dimForm,File,Version
PrivateSubClass_Initialize
dimiStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dimstrDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version=""
ifRequest.TotalBytes<1thenExitSub
setForm=CreateObject("Scripting.Dictionary")
setFile=CreateObject("Scripting.Dictionary")
setupfile_5xSoft_Stream=CreateObject("Adodb.Stream")
upfile_5xSoft_Stream.mode=3
upfile_5xSoft_Stream.type=1
upfile_5xSoft_Stream.open
upfile_5xSoft_Stream.writeRequest.BinaryRead(Request.TotalBytes)
vbEnter=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
whileiFormStart<iFormEnd
iStart=inString(iFormStart,"name=""")
iEnd=inString(iStart+6,"""")
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,"filename=""")
ifiFileNameStart>0andiFileNameStart<iFormEndthen
iFileNameEnd=inString(iFileNameStart+10,"""")
mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
ifiEnd>iStartthen
mFileSize=iEnd-iStart-4
else
mFileSize=0
endif
settheFile=newFileInfo
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=FormName
file.addmFormName,theFile
else
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
ifiEnd>iStartthen
mFormValue=subString(iStart+4,iEnd-iStart-4)
else
mFormValue=""
endif
form.AddmFormName,mFormValue
endif
iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
wend
EndSub
PrivateFunctionsubString(theStart,theLen)
dimi,c,stemp
upfile_5xSoft_Stream.Position=theStart-1
stemp=""
fori=1totheLen
ifupfile_5xSoft_Stream.EOSthenExitfor
c=ascB(upfile_5xSoft_Stream.Read(1))
Ifc>127Then
ifupfile_5xSoft_Stream.EOSthenExitfor
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
i=i+1
else
stemp=stemp&Chr(c)
EndIf
Next
subString=stemp
Endfunction
PrivateFunctioninString(theStart,varStr)
dimi,j,bt,theLen,str
InString=0
Str=toByte(varStr)
theLen=LenB(Str)
fori=theStarttoupfile_5xSoft_Stream.Size-theLen
ifi>upfile_5xSoft_Stream.sizethenexitFunction
upfile_5xSoft_Stream.Position=i-1
ifAscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1))then
InString=i
forj=2totheLen
ifupfile_5xSoft_Stream.EOSthen
inString=0
Exitfor
endif
ifAscB(upfile_5xSoft_Stream.Read(1))AscB(MidB(Str,j,1))then
InString=0
ExitFor
endif
next
ifInString0thenExitFunction
endif
next
EndFunction
PrivateSubClass_Terminate
form.RemoveAll
file.RemoveAll
setform=nothing
setfile=nothing
upfile_5xSoft_Stream.close
setupfile_5xSoft_Stream=nothing
EndSub
PrivatefunctionGetFilePath(FullPath)
IfFullPath""Then
GetFilePath=left(FullPath,InStrRev(FullPath,""))
Else
GetFilePath=""
EndIf
Endfunction
PrivatefunctionGetFileName(FullPath)
IfFullPath""Then
GetFileName=mid(FullPath,InStrRev(FullPath,"")+1)
Else
GetFileName=""
EndIf
Endfunction
PrivatefunctiontoByte(Str)
dimi,iCode,c,iLow,iHigh
toByte=""
Fori=1ToLen(Str)
c=mid(Str,i,1)
iCode=Asc(c)
IfiCode<0TheniCode=iCode+65535
IfiCode>255Then
iLow=Left(Hex(Asc(c)),2)
iHigh=Right(Hex(Asc(c)),2)
toByte=toByte&chrB("&H"&iLow)&chrB("&H"&iHigh)
Else
toByte=toByte&chrB(AscB(c))
EndIf
Next
Endfunction
EndClass
ClassFileInfo
dimFormName,FileName,FilePath,FileSize,FileStart
PrivateSubClass_Initialize
FileName=""
FilePath=""
FileSize=0
FileStart=0
FormName=""
EndSub
PublicfunctionSaveAs(FullPath)
dimdr,ErrorChar,i
SaveAs=1
iftrim(fullpath)=""orFileSize=0orFileStart=0orFileName=""thenexitfunction
ifFileStart=0orright(fullpath,1)="/"thenexitfunction
setdr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.copytodr,FileSize
dr.SaveToFileFullPath,2
dr.Close
setdr=nothing
SaveAs=0
endfunction
EndClass
</SCRIPT>
2,表单页面index.asp。注重框架包括的上传选择页upload.asp
<formname="form_name"method="POST"action="add.asp">
<textareacols="100"name="cn_content"rows="18"width="100%"></textarea>
</form>
<iframeborder="0"frameBorder="0"noResizescrolling="no"width="100%"src="upload.asp"></iframe>
3,上传选择页upload.asp注重:enctype="multipart/form-data"
<formname="form"method="post"action="upfile.asp"enctype="multipart/form-data">
<inputtype="hidden"name="filepath"value="uploadimg">
<inputtype="hidden"name="act"value="upload">
<inputtype="file"name="file1"size=40>
<inputtype="submit"class=buttonname="Submit"value="上传图片">范例:gif,jpg,限定:100K
</form>
4,最初一个文件upfile.asp次要感化:天生图片名,并将图片上传,一样也要将UBB标签写进index.asp中的textarea中。
<!--#includefile="upload.inc"-->
<html>
<head>
<title>文件上传</title>
</head>
<body>
<script>
parent.document.forms[0].Submit.disabled=false;
</script>
<%
dimupload,file,formName,formPath,iCount,filename,fileExt
setupload=newupload_5xSoft创建上传工具
formPath=upload.form("filepath")
在目次后加(/)
ifright(formPath,1)"/"thenformPath=formPath&"/"
response.write"<body>"
iCount=0
foreachformNameinupload.file列出一切上传了的文件
setfile=upload.file(formName)天生一个文件工具
iffile.filesize<100then
response.write"请选择你要上传的文件 [<ahref=#onclick=history.go(-1)>从头上传</a>]"
response.end
endif
iffile.filesize>100*1000then
response.write"文件巨细凌驾了限定100K [<ahref=#onclick=history.go(-1)>从头上传</a>]"
response.end
endif
fileExt=lcase(right(file.filename,4))
uploadsuc=false
Forum_upload="gif,jpg,png"
Forumupload=split(Forum_upload,",")
fori=0toubound(Forumupload)
iffileEXT="."&trim(Forumupload(i))then
uploadsuc=true
exitfor
else
uploadsuc=false
endif
next
ifuploadsuc=falsethen
response.write"文件格局不准确 [<ahref=#onclick=history.go(-1)>从头上传</a>]"
response.end
endif
randomize
ranNum=int(90000*rnd)+10000
filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&fileExt
iffile.FileSize>0then假如FileSize>0申明有文件数据
file.SaveAsServer.mappath(FileName)保留文件
fori=0toubound(Forumupload)
iffileEXT="."&trim(Forumupload(i))then
response.write"<script>parent.form_name.cn_content.value+=</script>"
exitfor
endif
next
iCount=iCount+1
endif
setpold=nothing
next
setupload=nothing删除此工具
HtmendiCount&"个文件上传停止!"
subHtmEnd(Msg)
setupload=nothing
response.write"上传乐成[<ahref=#onclick=history.go(-1)>持续上传</a>]"
response.end
endsub
%>
</body>
</html>
固然,坚持图片的文件夹uploadimg不克不及少
在实现ERP等高端的ASP应用时,用户需要提供核心的经营资料,需要ASP商有很高的信用度。楼上说交互性不好,太牵强了吧。在微软提供的一套框架中,利用asp做网站,开发效率高,使用人数少,减少不必要的开销。交互性是互动方式,是有开发人员决定的。 |
|