| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 665 人关注过本帖
标题:求助,能否帮忙解释一下代码,看糊涂了
只看楼主 加入收藏
xiaoshahai
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2009-10-11
结帖率:0
收藏
已结贴  问题点数:10 回复次数:2 
求助,能否帮忙解释一下代码,看糊涂了
Public Sub Open()
        if p_Error=-1 then
            p_Error=0
        else
            Exit Sub
        end if
        Dim lngRequestSize,binRequestData,strFormItem,strFileItem
        Const strSplit="'"">"
        lngRequestSize=Request.TotalBytes
        if lngRequestSize<1 then
            p_Error=3 '文件太小或没有选择文件
            Exit Sub
        end if
        binRequestData=Request.BinaryRead(lngRequestSize)
        binForm.Type = 1
        binForm.Open
        binForm.Write binRequestData

        Dim bCrLf,strSeparator,intSeparator
        bCrLf=ChrB(13)&ChrB(10)'回车和空格

        intSeparator=InstrB(1,binRequestData,bCrLf)-1
        strSeparator=LeftB(binRequestData,intSeparator)'提取分隔符回车和空格

        Dim p_start,p_end,strItem,strInam,intTemp,strTemp
        Dim strFtyp,strFnam,strFext,lngFsiz
        p_start=intSeparator+2
        Do
            p_end  =InStrB(p_start,binRequestData,bCrLf&bCrLf)+3
            binItem.Type=1
            binItem.Open
            binForm.Position=p_start
            binForm.CopyTo binItem,p_end-p_start
            binItem.Position=0
            binItem.Type=2
            binItem.Charset="gb2312"
            strItem=binItem.ReadText
            binItem.Close()

            p_start=p_end
            p_end  =InStrB(p_start,binRequestData,strSeparator)-1
            binItem.Type=1
            binItem.Open
            binForm.Position=p_start
            lngFsiz=p_end-p_start-2
            binForm.CopyTo binItem,lngFsiz

            intTemp=Instr(39,strItem,"""")
            strInam=Mid(strItem,39,intTemp-39)

            if Instr(intTemp,strItem,"filename=""")<>0 then
            if not objForm.Exists(strInam&"_From") then
                strFileItem=strFileItem&strSplit&strInam
                if binItem.Size<>0 then
                    intTemp=intTemp+13
                    strFtyp=Mid(strItem,Instr(intTemp,strItem,"Content-Type: ")+14)
                    strTemp=Mid(strItem,intTemp,Instr(intTemp,strItem,"""")-intTemp)
                    intTemp=InstrRev(strTemp,"\")
                    strFnam=Mid(strTemp,intTemp+1)
                    objForm.Add strInam&"_Type",strFtyp
                    objForm.Add strInam&"_Name",strFnam
                    objForm.Add strInam&"_Path",Left(strTemp,intTemp)
                    objForm.Add strInam&"_Size",lngFsiz
                    if Instr(intTemp,strTemp,".")<>0 then
                        strFext=Mid(strTemp,InstrRev(strTemp,".")+1)
                    else
                        strFext=""
                    end if
                    if left(strFtyp,6)="image/" then
                        binItem.Position=0
                        binItem.Type=1
                        strTemp=binItem.read(10)
                        if strcomp(strTemp,chrb(255) & chrb(216) & chrb(255) & chrb(224) & chrb(0) & chrb(16) & chrb(74) & chrb(70) & chrb(73) & chrb(70),0)=0 then
                            if Lcase(strFext)<>"jpg" then strFext="jpg"
                            binItem.Position=3
                            do while not binItem.EOS
                                do
                                    intTemp = ascb(binItem.Read(1))
                                loop while intTemp = 255 and not binItem.EOS
                                if intTemp < 192 or intTemp > 195 then
                                    binItem.read(Bin2Val(binItem.Read(2))-2)
                                else
                                    Exit do
                                end if
                                do
                                    intTemp = ascb(binItem.Read(1))
                                loop while intTemp < 255 and not binItem.EOS
                            loop
                            binItem.Read(3)
                            objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
                            objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
                        elseif strcomp(leftB(strTemp,8),chrb(137) & chrb(80) & chrb(78) & chrb(71) & chrb(13) & chrb(10) & chrb(26) & chrb(10),0)=0 then
                            if Lcase(strFext)<>"png" then strFext="png"
                            binItem.Position=18
                            objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
                            binItem.Read(2)
                            objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
                        elseif strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(57) & chrb(97),0)=0 or strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(55) & chrb(97),0)=0 then
                            if Lcase(strFext)<>"gif" then strFext="gif"
                            binItem.Position=6
                            objForm.Add strInam&"_Width",BinVal2(binItem.Read(2))
                            objForm.Add strInam&"_Height",BinVal2(binItem.Read(2))
                        elseif strcomp(leftB(strTemp,2),chrb(66) & chrb(77),0)=0 then
                            if Lcase(strFext)<>"bmp" then strFext="bmp"
                            binItem.Position=18
                            objForm.Add strInam&"_Width",BinVal2(binItem.Read(4))
                            objForm.Add strInam&"_Height",BinVal2(binItem.Read(4))
                        end if
                    end if
                    objForm.Add strInam&"_Ext",strFext
                    objForm.Add strInam&"_From",p_start
                    intTemp=GetFerr(lngFsiz,strFext)
                    if p_AutoSave<>2 then
                        objForm.Add strInam&"_Err",intTemp
                        if intTemp=0 then
                            if p_AutoSave=0 then
                                strFnam=GetTimeStr()
                                if strFext<>"" then strFnam=strFnam&"."&strFext
                            end if
                            binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
                            objForm.Add strInam,strFnam
                        end if
                    end if
                else
                    objForm.Add strInam&"_Err",-1
                end if
            end if
            else
                binItem.Position=0
                binItem.Type=2
                binItem.Charset="gb2312"
                strTemp=binItem.ReadText
                if objForm.Exists(strInam) then
                    objForm(strInam) = objForm(strInam)&","&strTemp
                else
                    strFormItem=strFormItem&strSplit&strInam
                    objForm.Add strInam,strTemp
                end if
            end if

            binItem.Close()
            p_start = p_end+intSeparator+2
        loop Until p_start+3>lngRequestSize
        FormItem=split(strFormItem,strSplit)
        FileItem=split(strFileItem,strSplit)
    End Sub
请解释的详细点,最好每个变量时是什么意思讲一下,这是ASP文件上传的部分代码,被写在一个类中了,先谢谢了!
搜索更多相关主题的帖子: 代码 糊涂 解释 
2009-10-29 18:47
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:5 
上传类的原理就是从传到服务器的二进制码里分析出文件的二进制代码,然后将文件的二进制代码写入服务器。
因为在计算机里任何文件都是以二进制代码的形式储存的
2009-10-30 12:35
hello103
Rank: 2
等 级:论坛游民
帖 子:19
专家分:52
注 册:2009-8-14
收藏
得分:5 
好晕哦,看这个
2009-10-30 13:12
快速回复:求助,能否帮忙解释一下代码,看糊涂了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036548 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved