中国站长下载-为中国站长提供最好最全的建站资源! 首 页发布资源有事留言繁體中文
设为首页
加入收藏
联系我们
 
您当前的位置:中国站长下载 -> 文章中心 -> 网页编程 -> ASP编程 -> 文章内容  虚拟主机 域名注册 退出登录 用户管理
栏目导航
· ASP编程 · .NET编程
· PHP编程 · JSP编程
· CGI 专区
热门文章
· sndvol32 - sndvol3...
· [组图] FLASH:《大话李白》...
· 个人网站到底能赚多...
· [图文] Rundll.exe是病毒吗...
· [组图] Flash:制作MV
· 价值12万元的网站SE...
· 网站创业者,你需要...
· 一个成功的网站设计...
· [图文] FLASH:韩国导航条解...
· 中国网站的赚钱模式...
相关文章
· DUDU的无组件上传例...
· [图文] 无组件上传图片至SQ...
· 无组件上传图片至SQ...
· ASP实例:6行代码实现...
· [图文] 无组件上传图片到数...
· 一个老个写的无组件...
· Asp无组件上传进度条...
无组件上传图片至SQLSERVER数据库(3)
作者:不详  来源:不详  发布时间:2006-8-13 0:20:59  发布人:chinazhan

 减小字体 增大字体

     '********************************** SeparateFields **********************************
  'This function retrieves the upload fields from binary data and retuns the fields as array
  'Binary is safearray of all raw binary data from input.
  Function SeparateFields(Binary, Boundary)
  Dim PosOpenBoundary, PosCloseBoundary, PosEndOfHeader, isLastBoundary
  Dim Fields
  Boundary = StringToBinary(Boundary)
  
  PosOpenBoundary = InstrB(Binary, Boundary)
  PosCloseBoundary = InstrB(PosOpenBoundary + LenB(Boundary), Binary, Boundary, 0)
  
  Set Fields = CreateObject("Scripting.Dictionary")
  
  Do While (PosOpenBoundary > 0 And PosCloseBoundary > 0 And Not isLastBoundary)
  'Header and file/source field data
  Dim HeaderContent, FieldContent
  'Header fields
  Dim Content_Disposition, FormFieldName, SourceFileName, Content_Type
  'Helping variables
  Dim Field, TwoCharsAfterEndBoundary
  'Get end of header
  PosEndOfHeader = InstrB(PosOpenBoundary + Len(Boundary), Binary, StringToBinary(vbCrLf + vbCrLf))
  
  'Separates field header
  HeaderContent = MidB(Binary, PosOpenBoundary + LenB(Boundary) + 2, PosEndOfHeader - PosOpenBoundary - LenB(Boundary) - 2)
  
  'Separates field content
  FieldContent = MidB(Binary, (PosEndOfHeader + 4), PosCloseBoundary - (PosEndOfHeader + 4) - 2)
  
  'Separates header fields from header
  GetHeadFields BinaryToString(HeaderContent), Content_Disposition, FormFieldName, SourceFileName, Content_Type
  
  'Create one field and assign parameters
  Set Field = CreateUploadField()
  Field.Name = FormFieldName
  Field.ContentDisposition = Content_Disposition
  Field.FilePath = SourceFileName
  Field.FileName = GetFileName(SourceFileName)
  Field.ContentType = Content_Type
  Field.Value = FieldContent
  Field.Length = LenB(FieldContent)
  
  Fields.Add FormFieldName, Field
  
  'Is this ending boundary ?
  TwoCharsAfterEndBoundary = BinaryToString(MidB(Binary, PosCloseBoundary + LenB(Boundary), 2))
  'Binary.Mid(PosCloseBoundary + Len(Boundary), 2).String
  isLastBoundary = TwoCharsAfterEndBoundary = "--"
  If Not isLastBoundary Then 'This is not ending boundary - go to next form field.
  PosOpenBoundary = PosCloseBoundary
  PosCloseBoundary = InStrB(PosOpenBoundary + LenB(Boundary), Binary, Boundary )
  End If
  Loop
  Set SeparateFields = Fields
  End Function
  
  '********************************** Utilities **********************************
  Function BinaryToString(str)
  strto = ""
  for i=1 to lenb(str)
  if AscB(MidB(str, i, 1)) > 127 then
  strto = strto & chr(Ascb(MidB(str, i, 1))*256+Ascb(MidB(str, i+1, 1)))
  i = i + 1
  else
  strto = strto & Chr(AscB(MidB(str, i, 1)))
  end if
  next
  BinaryToString=strto
  
  End Function
  
  Function StringToBinary(String)
  Dim I, B
  For I=1 to len(String)
  B = B & ChrB(Asc(Mid(String,I,1)))
  Next
  StringToBinary = B
  End Function
  
  'Separates header fields from upload header
  Function GetHeadFields(ByVal Head, Content_Disposition, Name, FileName, Content_Type)
  Content_Disposition = LTrim(SeparateField(Head, "content-disposition:", ";"))
  Name = (SeparateField(Head, "name=", ";")) 'ltrim
  If Left(Name, 1) = """" Then Name = Mid(Name, 2, Len(Name) - 2)
  FileName = (SeparateField(Head, "filename=", ";")) 'ltrim
  If Left(FileName, 1) = """" Then FileName = Mid(FileName, 2, Len(FileName) - 2)
  Content_Type = LTrim(SeparateField(Head, "content-type:", ";"))
  End Function
  
  'Separets one filed between sStart and sEnd
  Function SeparateField(From, ByVal sStart, ByVal sEnd)
  Dim PosB, PosE, sFrom
  sFrom = LCase(From)
  PosB = InStr(sFrom, sStart)
  If PosB > 0 Then
  PosB = PosB + Len(sStart)
  PosE = InStr(PosB, sFrom, sEnd)
  If PosE = 0 Then PosE = InStr(PosB, sFrom, vbCrLf)
  If PosE = 0 Then PosE = Len(sFrom) + 1
  SeparateField = Mid(From, PosB, PosE - PosB)
  Else
  SeparateField = Empty
  End If
  End Function
  
  'Separetes file name from the full path of file
  Function GetFileName(FullPath)
  Dim Pos, PosF
  PosF = 0
  For Pos = Len(FullPath) To 1 Step -1
  Select Case Mid(FullPath, Pos, 1)
  Case "/", "\": PosF = Pos + 1: Pos = 0
  End Select
  Next
  If PosF = 0 Then PosF = 1
  GetFileName = Mid(FullPath, PosF)
  End Function
  </SCRIPT>
  <SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
  //The function creates Field object.
  function CreateUploadField(){ return new uf_Init() }
  function uf_Init(){
  this.Name = null
  this.ContentDisposition = null
  this.FileName = null
  this.FilePath = null
  this.ContentType = null
  this.Value = null
  this.Length = null
  }
  </SCRIPT>
  
    做人要厚道,请注明转自chinazhan中国站长(www.ChinaZhan.com)。

 
[] [返回上一页] [打 印] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
中国站长下载
中国站长下载

本页只接受PR>=4 IT类站点连接,申请连接,谢谢您们的支持!希望我们的下载站能够真正帮到中国的站长们!
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图
Copyright © 2005-2006 ChinaZhan.Net. All Rights Reserved .