真正的无组件上传,而且也不用数据库(转载)


所属类别:Asp

文章作者:佚名

特别推荐:免费发布信息 承包关键词~~抢爆了!HOT!


upload.htm----------------------------------Untitled Document<!--td {font-size: 9pt}a {color: #000000; text-decoration: none}a:hover {text-decoration: underline}.tx {height: 16px; width: 30px; border-color: black black #000000; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; font-size: 9pt; background-color: #eeeeee; color: #0000FF}.bt {font-size: 9pt; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; height: 16px; width: 80px; background-color: #eeeeee; cursor: hand}.tx1 { height: 20px; width: 30px; font-size: 9pt; border: 1px solid; border-color: black black #000000; color: #0000FF}--> 文件上传化境编程界文件上传function setid(){str='';if(!window.form1.upcount.value)window.form1.upcount.value=1;for(i=1;i<=window.form1.upcount.value;i++)str+='文件'+i+':';window.upid.innerHTML=str+'';} 需要上传的个数上传到: 文件1:setid();-------------------------------------upfile.asp<%OPTION EXPLICIT%><!--#include FILE="upload_5xsoft.inc"-->文件上传化境文件上传!<%dim upload,file,formName,formPath,iCountset upload=new upload_5xSoft '建立上传对象response.write upload.Version&""'显示上传类的版本if upload.form("filepath")="" then'得到上传目录 HtmEnd "请输入要上传至的目录!" set upload=nothing response.endelse formPath=upload.form("filepath") '在目录后加(/) if right(formPath,1)<>"/" then formPath=formPath&"/"end ifiCount=0for each formName in upload.file '列出所有上传了的文件 set file=upload.file(formName)'生成一个文件对象 if file.FileSize>0 then'如果 FileSize > 0 说明有文件数据file.SaveAs Server.mappath(formPath&file.FileName)'保存文件response.write file.FilePath&file.FileName&" ("&file.FileSize&") => "&formPath&File.FileName&" 成功!"iCount=iCount+1 end if set file=nothingnextset upload=nothing'删除此对象Htmend iCount&" 个文件上传结束!"sub HtmEnd(Msg) set upload=nothing response.write ""&Msg&" [返回]" response.endend sub%>-----------------------upload_5xsoft.inc'''''''''''''''''''''''''''请保留此信息: 稻香老农制作 http://www.5xSoft.com/''''''''''''''''''''''''''dim upfile_5xSoft_StreamClass upload_5xSoftdim Form,File,VersionPrivate Sub Class_Initializedim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFiledim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStrVersion="化境编程界HTTP上传程序 Version 1.0"if Request.TotalBytes<1 then Exit Subset Form=CreateObject("Scripting.Dictionary")set File=CreateObject("Scripting.Dictionary")set upfile_5xSoft_Stream=CreateObject("Adodb.Stream")upfile_5xSoft_Stream.mode=3upfile_5xSoft_Stream.type=1upfile_5xSoft_Stream.openupfile_5xSoft_Stream.write Request.BinaryRead(Request.TotalBytes)vbEnter=Chr(13)&Chr(10)iDivLen=inString(1,vbEnter)+1strDiv=subString(1,iDivLen)iFormStart=iDivLeniFormEnd=inString(iformStart,strDiv)-1while iFormStart < iFormEndiStart=inString(iFormStart,"name=""")iEnd=inString(iStart+6,"""")mFormName=subString(iStart+6,iEnd-iStart-6)iFileNameStart=inString(iEnd+1,"filename=""")if iFileNameStart>0 and iFileNameStartiStart thenmFileSize=iEnd-iStart-4elsemFileSize=0end ifset theFile=new FileInfotheFile.FileName=getFileName(mFileName)theFile.FilePath=getFilePath(mFileName)theFile.FileSize=mFileSizetheFile.FileStart=iStart+4theFile.FormName=FormNamefile.add mFormName,theFileelseiStart=inString(iEnd+1,vbEnter&vbEnter)iEnd=inString(iStart+4,vbEnter&strDiv)if iEnd>iStart thenmFormValue=subString(iStart+4,iEnd-iStart-4)elsemFormValue=""end ifform.Add mFormName,mFormValueend ifiFormStart=iformEnd+iDivLeniFormEnd=inString(iformStart,strDiv)-1wendEnd SubPrivate Function subString(theStart,theLen) dim i,c,stemp upfile_5xSoft_Stream.Position=theStart-1 stemp="" for i=1 to theLenif upfile_5xSoft_Stream.EOS then Exit forc=ascB(upfile_5xSoft_Stream.Read(1))If c > 127 Thenif upfile_5xSoft_Stream.EOS then Exit forstemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))i=i+1elsestemp=stemp&Chr(c)End If Next subString=stempEnd functionPrivate Function inString(theStart,varStr) dim i,j,bt,theLen,str InString=0 Str=toByte(varStr) theLen=LenB(Str) for i=theStart to upfile_5xSoft_Stream.Size-theLenif i>upfile_5xSoft_Stream.size then exit Functionupfile_5xSoft_Stream.Position=i-1if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) thenInString=ifor j=2 to theLenif upfile_5xSoft_Stream.EOS theninString=0Exit forend ifif AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) thenInString=0Exit Forend ifnextif InString<>0 then Exit Functionend if nextEnd FunctionPrivate Sub Class_Terminateform.RemoveAllfile.RemoveAllset form=nothingset file=nothingupfile_5xSoft_Stream.closeset upfile_5xSoft_Stream=nothingEnd Sub Private function GetFilePath(FullPath)If FullPath <> "" ThenGetFilePath = left(FullPath,InStrRev(FullPath, "\"))ElseGetFilePath = ""End If Endfunction Private function GetFileName(FullPath)If FullPath <> "" ThenGetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)ElseGetFileName = ""End If Endfunction Private function toByte(Str)dim i,iCode,c,iLow,iHightoByte=""For i=1 To Len(Str)c=mid(Str,i,1)iCode =Asc(c)If iCode<0 Then iCode = iCode + 65535If iCode>255 TheniLow = Left(Hex(Asc(c)),2)iHigh =Right(Hex(Asc(c)),2)toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)ElsetoByte = toByte & chrB(AscB(c))End IfNext End functionEnd ClassClass FileInfodim FormName,FileName,FilePath,FileSize,FileStartPrivate Sub Class_InitializeFileName = ""FilePath = ""FileSize = 0FileStart= 0FormName = ""End Sub Public function SaveAs(FullPath)dim dr,ErrorChar,iSaveAs=1if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit functionif FileStart=0 or right(fullpath,1)="/" then exit functionset dr=CreateObject("Adodb.Stream")dr.Mode=3dr.Type=1dr.Openupfile_5xSoft_Stream.position=FileStart-1upfile_5xSoft_Stream.copyto dr,FileSizedr.SaveToFile FullPath,2dr.Closeset dr=nothingSaveAs=0end functionEnd Class

关闭本页

相关信息

· 防火墙功能指标详解

· 无法打开exe可执行文件的解决方案

· vb 中 创建的EXCEL 对象无法在WIN98中office2000中显示(在XP的OFFICE2000中可以)

· 酷软:网易相册上传好帮手








....

23637 10292