• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    《支持中文的無組件文件上傳》-- upload.inc

    發布: 2007-6-30 18:56 | 作者: admin | 來源: | 查看: 11次 | 進入軟件測試論壇討論

    領測軟件測試網 作者:woozhj
    文件名:upload.inc
    說明:支持中文的無組件文件上傳ASP函數,由于ASP不支持二進制寫入文件,所以存成文件時必須使用組件,本函數只提供截取上傳文件的數據,可以寫入到數據庫。

    <SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
    Function GetUpload(FormData)
        Dim DataStart,DivStr,DivLen,DataSize,FormFieldData
        ‘’分隔標志串(+CRLF)
        DivStr = LeftB(FormData,InStrB(FormData,str2bin(VbCrLf)) + 1)
        ‘’分隔標志串長度
        DivLen = LenB(DivStr)
        PosOpenBoundary = InStrB(FormData,DivStr)
        PosCloseBoundary = InStrB(PosOpenBoundary + 1,FormData,DivStr)
        Set Fields = CreateObject("Scripting.Dictionary")
       
        While PosOpenBoundary > 0 And PosCloseBoundary > 0
           ‘’name起始位置(name="xxxxx"),加6是因為[name="]長度為6
           FieldNameStart = InStrB(PosOpenBoundary,FormData,str2bin("name=")) + 6
           FieldNameSize = InStrB(FieldNameStart,FormData,ChrB(34)) - FieldNameStart ‘’(")的ASC值=34
           FormFieldName = bin2str(MidB(FormData,FieldNameStart,FieldNameSize))
           
           ‘’filename起始位置(filename="xxxxx")
           FieldFileNameStart = InStrB(PosOpenBoundary,FormData,str2bin("filename=")) + 10
           If FieldFileNameStart < PosCloseBoundary And FieldFileNameStart > PosopenBoundary Then
              FieldFileNameSize = InStrB(FieldFileNameStart,FormData,ChrB(34)) - FieldFileNameStart ‘’(")的ASC值=34
              FormFileName = bin2str(MidB(FormData,FieldFileNameStart,FieldFileNameSize))
           Else
              FormFileName = ""
           End If
           
           ‘’Content-Type起始位置(Content-Type: xxxxx)
           FieldFileCTStart = InStrB(PosOpenBoundary,FormData,str2bin("Content-Type:")) + 14
           If FieldFileCTStart < PosCloseBoundary  And FieldFileCTStart > PosOpenBoundary Then
              FieldFileCTSize = InStrB(FieldFileCTStart,FormData,str2bin(VbCrLf & VbCrLf)) - FieldFileCTStart
              FormFileCT = bin2str(MidB(FormData,FieldFileCTStart,FieldFileCTSize))
           Else
              FormFileCT = ""
           End If
           
           ‘’數據起始位置:2個CRLF開始
           DataStart = InStrB(PosOpenBoundary,FormData,str2bin(VbCrLf & VbCrLf)) + 4
           If FormFileName <> "" Then
              ‘’數據長度,減1是因為數據文件的存取字節數問題(可能是AppendChunk方法的問題):
              ‘’由于字節數為奇數的圖象存到數據庫時會去掉最后一個字符導致圖象不能正確顯示,
              ‘’字節數為偶數的數據文件就不會出現這個問題,因此必須保持字節數為偶數。
              DataSize = InStrB(DataStart,FormData,DivStr) - DataStart - 1
              FormFieldData = MidB(FormData,DataStart,DataSize)
           Else
              ‘’數據長度,減2是因為分隔標志串前有一個CRLF
              DataSize = InStrB(DataStart,FormData,DivStr) - DataStart - 2
              FormFieldData = bin2str(MidB(FormData,DataStart,DataSize))
           End If

           ‘’建立一個Dictionary集存儲Form中各個Field的相關數據
           Set Field = CreateUploadField()
           Field.Name = FormFieldName
           Field.FilePath = FormFileName
           Field.FileName = GetFileName(FormFileName)
           Field.ContentType = FormFileCT
           Field.Length = LenB(FormFieldData)
           Field.Value = FormFieldData
           
           Fields.Add FormFieldName, Field
           
           PosOpenBoundary = PosCloseBoundary
           PosCloseBoundary = InStrB(PosOpenBoundary + 1,FormData,DivStr)
        Wend
        Set GetUpload = Fields
    End Function

    ‘’把二進制字符串轉換成普通字符串函數
    Function bin2str(binstr)
       Dim varlen,clow,ccc,skipflag
       ‘’中文字符Skip標志
       skipflag=0
       ccc = ""
       If Not IsNull(binstr) Then
          varlen=LenB(binstr)
          For i=1 To varlen
              If skipflag=0 Then
                 clow = MidB(binstr,i,1)
                 ‘’判斷是否中文的字符
                 If AscB(clow) > 127 Then
                    ‘’AscW會把二進制的中文雙字節字符高位和低位反轉,所以要先把中文的高低位反轉
                    ccc =ccc & Chr(AscW(MidB(binstr,i+1,1) & clow))
                    skipflag=1
                 Else
                    ccc = ccc & Chr(AscB(clow))
                 End If
              Else
                 skipflag=0
              End If
          Next
       End If
       bin2str = ccc
    End Function


    ‘’把普通字符串轉成二進制字符串函數
    Function str2bin(varstr)
       str2bin=""
       For i=1 To Len(varstr)
           varchar=mid(varstr,i,1)
           varasc = Asc(varchar)
           ‘’ asc對中文字符求出來的值可能為負數,
           ‘’ 加上65536就可求出它的無符號數值
           ‘’ -1在機器內是用補碼表示的0xffff,
           ‘’ 其無符號值為65535,65535=-1+65536
           ‘’ 其他負數依次類推。
           If varasc<0 Then
              varasc = varasc + 65535
           End If
           ‘’對中文的處理:把雙字節低位和高位分開
           If varasc>255 Then
              varlow = Left(Hex(Asc(varchar)),2)
              varhigh = right(Hex(Asc(varchar)),2)
              str2bin = str2bin & chrB("&H" & varlow) & chrB("&H" & varhigh)
           Else
              str2bin = str2bin & chrB(AscB(varchar))
           End If
       Next
    End Function

    ‘’取得文件名(去掉Path)
    Function GetFileName(FullPath)
       If FullPath <> "" Then
          FullPath = StrReverse(FullPath)
          FullPath = Left(FullPath, InStr(1, FullPath, "\") - 1)
          GetFileName = StrReverse(FullPath)
       Else
          GetFileName = ""
       End If
    End Function
    </SCRIPT>
    <SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
    function CreateUploadField(){ return new uf_Init() }
    function uf_Init(){
      this.Name = null
      this.FileName = null
      this.FilePath = null
      this.ContentType = null
      this.Value = null
      this.Length = null
    }
    </SCRIPT>

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>