风声无组件上传类[1]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 applebbs 的 blog

程序代码:
<%
'----------------------------------------------------------
'*****************  风声无组件上传类 2.0  *****************
'作者:风声
'网站:http://www.17560.net http://www.54nb.com
'邮件:rumor@17560.net
'版权:版权全体,源代码公开,各种用途均可免费使用
'**********************************************************
'----------------------------------------------------------
class uploadclass

 private p_maxsize,p_filetype,p_savepath,p_autosave,p_error
 private objform,binform,binitem,strdate,lngtime
 public formitem,fileitem

 public property get version
  version="rumor uploadclass version 2.0"
 end property

 public property get error
  error=p_error
 end property

 public property get maxsize
  maxsize=p_maxsize
 end property
 public property let maxsize(lngsize)
  if isnumeric(lngsize) then
   p_maxsize=clng(lngsize)
  end if
 end property

 public property get filetype
  filetype=p_filetype
 end property
 public property let filetype(strtype)
  p_filetype=strtype
 end property

 public property get savepath
  savepath=p_savepath
 end property
 public property let savepath(strpath)
  p_savepath=replace(strpath,chr(0),"")
 end property

 public property get autosave
  autosave=p_autosave
 end property
 public property let autosave(byval flag)
  select case flag
   case 0:
   case 1:
   case 2:
   case false:flag=2
   case else:flag=0
  end select
  p_autosave=flag
 end property

 private sub class_initialize
  p_error    = -1
  p_maxsize  = 153600
  p_filetype = "jpg/gif"
  p_savepath = ""
  p_autosave = 0
  strdate    = replace(cstr(date()),"-","")
  lngtime    = clng(timer()*1000)
  set binform = server.createobject("adodb.stream")
  set binitem = server.createobject("adodb.stream")
  set objform = server.createobject("scripting.dictionary")
  objform.comparemode = 1
 end sub

 private sub class_terminate
  objform.removeall
  set objform = nothing
  set binitem = nothing
  binform.close()
  set binform = nothing
 end sub

 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=4
   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))

本文关键:风声无组件上传类
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top