欢迎光临
我们一直在努力

关于无组上传的老话题-ASP教程,ASP应用

建站超值云服务器,限时71元/月

<script runat=server language=vbscript>

dim data_5xsoft

class upload_5xsoft

dim objform,objfile,version

public function form(strform)

strform=lcase(strform)

if not objform.exists(strform) then

form=""

else

form=objform(strform)

end if

end function

public function file(strfile)

strfile=lcase(strfile)

if not objfile.exists(strfile) then

set file=new fileinfo

else

set file=objfile(strfile)

end if

end function

private sub class_initialize

dim requestdata,sstart,vbcrlf,sinfo,iinfostart,iinfoend,tstream,istart,thefile

dim ifilesize,sfilepath,sfiletype,sformvalue,sfilename

dim ifindstart,ifindend

dim iformstart,iformend,sformname

dim dataend,image,head_height_l,head_height_h

version="化境http上传程序 version 2.0"

set objform=server.createobject("scripting.dictionary")

set objfile=server.createobject("scripting.dictionary")

if request.totalbytes<1 then exit sub

set tstream = server.createobject("adodb.stream")

set data_5xsoft = server.createobject("adodb.stream")

data_5xsoft.type = 1

data_5xsoft.mode =3

data_5xsoft.open

data_5xsoft.write request.binaryread(request.totalbytes)

data_5xsoft.position=0

requestdata =data_5xsoft.read

iformstart = 1

iformend = lenb(requestdata)

vbcrlf = chrb(13) & chrb(10)

sstart = midb(requestdata,1, instrb(iformstart,requestdata,vbcrlf)-1)

istart = lenb (sstart)

iformstart=iformstart+istart+1

while (iformstart + 10) < iformend

iinfoend = instrb(iformstart,requestdata,vbcrlf & vbcrlf)+3

tstream.type = 1

tstream.mode =3

tstream.open

data_5xsoft.position = iformstart

data_5xsoft.copyto tstream,iinfoend-iformstart

tstream.position = 0

tstream.type = 2

tstream.charset ="gb2312"

sinfo = tstream.readtext

tstream.close

取得表单项目名称

iformstart = instrb(iinfoend,requestdata,sstart)

ifindstart = instr(22,sinfo,"name=""",1)+6

ifindend = instr(ifindstart,sinfo,"""",1)

sformname = lcase(mid (sinfo,ifindstart,ifindend-ifindstart))

如果是文件

if instr (45,sinfo,"filename=""",1) > 0 then

set thefile=new fileinfo

取得图片长宽

dataend = iformstart-iinfoend-1

image=midb(sinfo,iinforend+1,dataend)

head_height_l = ascb( midb( image,165,1 ) )

head_height_h = ascb( midb( image,164,1 ) )

head_width_l = ascb( midb( image,167,1 ) )

head_width_h = ascb( midb( image,166,1 ) )

head_width_h = head_width_h * 256

head_height_h = head_height_h * 256

jpgwidth= head_width_h + head_width_l

jpgheight=head_height_h + head_height_l

取得文件名

ifindstart = instr(ifindend,sinfo,"filename=""",1)+10

ifindend = instr(ifindstart,sinfo,"""",1)

sfilename = mid (sinfo,ifindstart,ifindend-ifindstart)

thefile.filename=getfilename(sfilename)

thefile.filepath=getfilepath(sfilename)

取得文件类型

ifindstart = instr(ifindend,sinfo,"content-type: ",1)+14

ifindend = instr(ifindstart,sinfo,vbcr)

thefile.filetype =mid (sinfo,ifindstart,ifindend-ifindstart)

thefile.filestart =iinfoend

thefile.filesize = iformstart -iinfoend -3

thefile.formname=sformname

if not objfile.exists(sformname) then

objfile.add sformname,thefile

end if

else

如果是表单项目

tstream.type =1

tstream.mode =3

tstream.open

data_5xsoft.position = iinfoend

data_5xsoft.copyto tstream,iformstart-iinfoend-3

tstream.position = 0

tstream.type = 2

tstream.charset ="gb2312"

sformvalue = tstream.readtext

tstream.close

if objform.exists(sformname) then

objform(sformname)=objform(sformname)&", "&sformvalue

else

objform.add sformname,sformvalue

end if

end if

iformstart=iformstart+istart+1

wend

requestdata=""

set tstream =nothing

end sub

private sub class_terminate

if request.totalbytes>0 then

objform.removeall

objfile.removeall

set objform=nothing

set objfile=nothing

data_5xsoft.close

set data_5xsoft =nothing

end if

end sub

private function getfilepath(fullpath)

if fullpath <> "" then

getfilepath = left(fullpath,instrrev(fullpath, "\"))

else

getfilepath = ""

end if

end function

private function getfilename(fullpath)

if fullpath <> "" then

getfilename = mid(fullpath,instrrev(fullpath, "\")+1)

else

getfilename = ""

end if

end function

end class

class fileinfo

dim formname,filename,filepath,filesize,filetype,filestart

private sub class_initialize

filename = ""

filepath = ""

filesize = 0

filestart= 0

formname = ""

filetype = ""

end sub

public function saveas(fullpath)

dim dr,errorchar,i

saveas=true

if trim(fullpath)="" or filestart=0 or filename="" or right(fullpath,1)="/" then exit function

set dr=createobject("adodb.stream")

dr.mode=3

dr.type=1

dr.open

data_5xsoft.position=filestart

data_5xsoft.copyto dr,filesize

dr.savetofile fullpath,2

dr.close

set dr=nothing

saveas=false

end function

end class

</script>

stream流的问题:sstart = midb(requestdata,1, instrb(iformstart,requestdata,vbcrlf)-1)为段落之间的分割符号

iinfoend = instrb(iformstart,requestdata,vbcrlf & vbcrlf)+3 此点前为value,后面是文件的info

iinfoend到sstart之间是一个文件的info

用iformstart控制各个开始点

stream type

type=1 means adtypebinary

mode 3 是可读写

method

open打开个空流

write 向流写入二进制数据

method

request.binaryread 读取原始未解析的内容

request.totalbytes 返回所有字节数

position 当前指针的位置

read 从当前位置顺序读取

lenb 返回字符有多少

chrb 不是返回一个或两个字节的字符,而总是返回单个字节的字符。

instrb 返回的不是一个字符串在另一个字符串中第一次出现的字符位置,而是字节位置。

midb 函数与包含在字符串中的字节数据一起使用。其参数不是指定字符数,而是字节数。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 关于无组上传的老话题-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章