欢迎光临
我们一直在努力

一个老个写的无组件上传,呵呵。有意思。

建站超值云服务器,限时71元/月

<!–#include file="../lib/filelib.asp"–>
<%
    response.write "<title>上传文件至当前文件夹</title>"
    response.write "<body bgcolor=""#d6d3ce"" leftmargin=""0"" topmargin=""0"" title = ""    请您遵守国家相关法律法规上传文件。上传前请杀毒,否则系统将会自动删除此文件!"">"

**start encode**
action=request("a")
if action="ul" then
        doupload request.cookies("dazhou.net")("nowpath") & "\"
        checkdiskspace
        response.redirect "fileman.asp"
else
    showuploadform
end if

set fso=nothing
========================
sub showuploadform
========================
    response.write "<dir><form enctype=multipart/form-data name=fmupload method=post action=upload.asp?a=ul><br>"
    if request("n")<>"" and isnumeric(request("n")) then session("numuploadfields")=cint(request("n"))
    for i=1 to 5
        response.write "<input type=file name=file"& i & " size=35><br>"
    next
    response.write "<br><center><input type=submit value=""开始上传"">  <input type=button value= 取消上传 onclick=window.close()> "
    response.write "</form>"
end sub

========================
sub doupload(dir)
========================
    if not application("debugging") then on error resume next
    starttime=now
    requestbin=request.binaryread(request.totalbytes)
    set uploadrequest=createobject("scripting.dictionary")
    builduploadrequest requestbin, uploadrequest
    keys=uploadrequest.keys
    for i=0 to uploadrequest.count – 1
        curkey=keys(i)
        fname=uploadrequest.item(curkey).item("filename")

        if fso.fileexists(dir & fname) then fso.deletefile dir & fname
        if fname<>"" and not fso.fileexists(dir & fname) then
            value=uploadrequest.item(curkey).item("value")
            valuebeg=uploadrequest.item(curkey).item("valuebeg")
            valuelen=uploadrequest.item(curkey).item("valuelen")
            totalulsize=totalulsize + valuelen
            set strm1=server.createobject("adodb.stream")
            set strm2=server.createobject("adodb.stream")
            strm1.open
            strm1.type=1 binary
            strm2.open
            strm2.type=1 binary
            strm1.write requestbin
            strm1.position=valuebeg
            strm1.copyto strm2,valuelen
            strm2.savetofile dir & fname,2
            set strm1=nothing
            set strm2=nothing
        end if
     next
    if now>starttime then response.write("<br><br><br><br><center>上传成功!<br>速度: " & round(totalulsize/1024/datediff("s",starttime,now)) &" 千字节/秒" )
    set uploadrequest=nothing
end sub

========================
sub builduploadrequest(requestbin, uploadrequest)
========================
    get the boundary
    posbeg=1
    posend=instrb(posbeg,requestbin,getbytestring(chr(13)))
    boundary=midb(requestbin,posbeg,posend-posbeg)
    boundarypos=instrb(1,requestbin,boundary)
    get all data inside the boundaries
    do until (boundarypos=instrb(requestbin,boundary & getbytestring("–")))
        members variable of objects are put in a dictionary object
        dim uploadcontrol
        set uploadcontrol=createobject("scripting.dictionary")
        get an object name
        pos=instrb(boundarypos,requestbin,getbytestring("content-disposition"))
        pos=instrb(pos,requestbin,getbytestring("name="))
        posbeg=pos+6
        posend=instrb(posbeg,requestbin,getbytestring(chr(34)))
        name=getstring(midb(requestbin,posbeg,posend-posbeg))
        posfile=instrb(boundarypos,requestbin,getbytestring("filename="))
        posbound=instrb(posend,requestbin,boundary)
        test if object is of file type
        if posfile<>0 and (posfile<posbound) then
            get filename, content-type and content of file
            posbeg=posfile + 10
            posend=instrb(posbeg,requestbin,getbytestring(chr(34)))
            filename=getstring(midb(requestbin,posbeg,posend-posbeg))
            filename=mid(filename,instrrev(filename,"\")+1)
            add filename to dictionary object
            uploadcontrol.add "filename", filename
            pos=instrb(posend,requestbin,getbytestring("content-type:"))
            posbeg=pos+14
            posend=instrb(posbeg,requestbin,getbytestring(chr(13)))
            add content-type to dictionary object
            contenttype=getstring(midb(requestbin,posbeg,posend-posbeg))
            uploadcontrol.add "contenttype",contenttype
            get content of object
            posbeg=posend+4
            posend=instrb(posbeg,requestbin,boundary)-2
            value=filename
            valuebeg=posbeg-1
            valuelen=posend-posbeg
        else
            get content of object
            pos=instrb(pos,requestbin,getbytestring(chr(13)))
            posbeg=pos+4
            posend=instrb(posbeg,requestbin,boundary)-2
            value=getstring(midb(requestbin,posbeg,posend-posbeg))
            valuebeg=0
            valueend=0
        end if
        uploadcontrol.add "value" , value
        uploadcontrol.add "valuebeg" , valuebeg
        uploadcontrol.add "valuelen" , valuelen
        uploadrequest.add name, uploadcontrol
        boundarypos=instrb(boundarypos+lenb(boundary),requestbin,boundary)
    loop
end sub

====================================
function getbytestring(stringstr)
====================================
    for i=1 to len(stringstr)
         char=mid(stringstr,i,1)
        getbytestring=getbytestring & chrb(ascb(char))
    next
end function

====================================
function getstring(stringbin)
====================================
    getstring =""
    for intcount=1 to lenb(stringbin)
        getstring=getstring & chr(ascb(midb(stringbin,intcount,1)))
    next
end function
%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 一个老个写的无组件上传,呵呵。有意思。
分享到: 更多 (0)