WEB开发网
开发学院WEB开发ASP ASP技巧实例:关于对表单操作的程序 阅读

ASP技巧实例:关于对表单操作的程序

 2007-09-25 12:05:02 来源:WEB开发网   
核心提示:InsertingFormcontentintoDatabasewithASP.<%'--Loader.asp--'--version1.5.2'--lastupdated12/5/2002''FaisalKhan'faisal@stardeveloper.com&

InsertingFormcontentintoDatabasewithASP.

<%
 '--Loader.asp--
 '--version1.5.2
 '--lastupdated12/5/2002
 '
 'FaisalKhan
 'faisal@stardeveloper.com
 'www.stardeveloper.com
 'Classforhandlingbinaryuploads
 ClassLoader
  Privatedict
  
  PrivateSubClass_Initialize
   Setdict=Server.CreateObject("Scripting.Dictionary")
  EndSub
  PrivateSubClass_Terminate
   IfIsObject(intDict)Then
    intDict.RemoveAll
    SetintDict=Nothing
   EndIf
   IfIsObject(dict)Then
    dict.RemoveAll
    Setdict=Nothing
   EndIf
  EndSub
  PublicPropertyGetCount
   Count=dict.Count
  EndProperty
  PublicSubInitialize
   IfRequest.TotalBytes>0Then
    DimbinData
     binData=Request.BinaryRead(Request.TotalBytes)
     getDatabinData
   EndIf
  EndSub
  PublicFunctiongetFileData(name)
   Ifdict.Exists(name)Then
    getFileData=dict(name).Item("Value")
    Else
    getFileData=""
   EndIf
  EndFunction
  PublicFunctiongetValue(name)
   Dimgv
   Ifdict.Exists(name)Then
    gv=CStr(dict(name).Item("Value"))
    
    gv=Left(gv,Len(gv)-2)
    getValue=gv
   Else
    getValue=""
   EndIf
  EndFunction
  PublicFunctionsaveToFile(name,path)
   Ifdict.Exists(name)Then
    Dimtemp
     temp=dict(name).Item("Value")
    Dimfso
     Setfso=Server.CreateObject("Scripting.FileSystemObject")
    Dimfile
     Setfile=fso.CreateTextFile(path)
      FortPoint=1toLenB(temp)
        file.WriteChr(AscB(MidB(temp,tPoint,1)))
      Next
      file.Close
     saveToFile=True
   Else
     saveToFile=False
   EndIf
  EndFunction
  PublicFunctiongetFileName(name)
   Ifdict.Exists(name)Then
    Dimtemp,tempPos
     temp=dict(name).Item("FileName")
     tempPos=1+InStrRev(temp,"")
     getFileName=Mid(temp,tempPos)
   Else
    getFileName=""
   EndIf
  EndFunction
  PublicFunctiongetFilePath(name)
   Ifdict.Exists(name)Then
    Dimtemp,tempPos
     temp=dict(name).Item("FileName")
     tempPos=InStrRev(temp,"")
     getFilePath=Mid(temp,1,tempPos)
   Else
    getFilePath=""
   EndIf
  EndFunction
  PublicFunctiongetFilePathComplete(name)
   Ifdict.Exists(name)Then
    getFilePathComplete=dict(name).Item("FileName")
   Else
    getFilePathComplete=""
   EndIf
  EndFunction
  PublicFunctiongetFileSize(name)
   Ifdict.Exists(name)Then
    getFileSize=LenB(dict(name).Item("Value"))
   Else
    getFileSize=0
   EndIf
  EndFunction
  PublicFunctiongetFileSizeTranslated(name)
   Ifdict.Exists(name)Then
    temp=LenB(dict(name).Item("Value"))
     Iftemp<=1024Then
      getFileSizeTranslated=temp&"bytes" 
     Else
      temp=FormatNumber((temp/1024),2)
      getFileSizeTranslated=temp&"kilobytes"
     EndIf
   Else
    getFileSizeTranslated=""
   EndIf
  EndFunction
  PublicFunctiongetContentType(name)
   Ifdict.Exists(name)Then
    getContentType=dict(name).Item("ContentType")
   Else
    getContentType=""
   EndIf
  EndFunction
 PrivateSubgetData(rawData)
  Dimseparator
   separator=MidB(rawData,1,InstrB(1,rawData,ChrB(13))-1)
  DimlenSeparator
   lenSeparator=LenB(separator)
  DimcurrentPos
   currentPos=1
  DiminStrByte
   inStrByte=1
  Dimvalue,mValue
  DimtempValue
   tempValue=""
  WhileinStrByte>0
   inStrByte=InStrB(currentPos,rawData,separator)
   mValue=inStrByte-currentPos
   IfmValue>1Then
    value=MidB(rawData,currentPos,mValue)
    DimbegPos,endPos,midValue,nValue
    DimintDict
     SetintDict=Server.CreateObject("Scripting.Dictionary")
     begPos=1+InStrB(1,value,ChrB(34))
     endPos=InStrB(begPos+1,value,ChrB(34))
     nValue=endPos
    DimnameN
     nameN=MidB(value,begPos,endPos-begPos)
    DimnameValue,isValid
     isValid=True
     
     IfInStrB(1,value,stringToByte("Content-Type"))>1Then
      begPos=1+InStrB(endPos+1,value,ChrB(34))
      endPos=InStrB(begPos+1,value,ChrB(34))
      IfendPos=0Then
       endPos=begPos+1
       isValid=False
      EndIf
      midValue=MidB(value,begPos,endPos-begPos)
       intDict.Add"FileName",trim(byteToString(midValue))
     begPos=14+InStrB(endPos+1,value,stringToByte("Content-Type:"))
     endPos=InStrB(begPos,value,ChrB(13))
      midValue=MidB(value,begPos,endPos-begPos)
       intDict.Add"ContentType",trim(byteToString(midValue))
      begPos=endPos+4
      endPos=LenB(value)
      nameValue=MidB(value,begPos,((endPos-begPos)-1))
     Else
      nameValue=trim(byteToString(MidB(value,nValue+5)))
     EndIf
     IfisValid=TrueThen
      intDict.Add"Value",nameValue
      intDict.Add"Name",nameN
      dict.AddbyteToString(nameN),intDict
     EndIf
   EndIf
   currentPos=lenSeparator+inStrByte
  Wend
 EndSub
 
 EndClass
 PrivateFunctionstringToByte(toConv)
  DimtempChar
  Fori=1toLen(toConv)
   tempChar=Mid(toConv,i,1)
   stringToByte=stringToByte&chrB(AscB(tempChar))
  Next
 EndFunction
 PrivateFunctionbyteToString(toConv)
  Fori=1toLenB(toConv)
   byteToString=byteToString&Chr(AscB(MidB(toConv,i,1)))
  Next
 EndFunction
%>

1 2  下一页

Tags:ASP 技巧 实例

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接