asp批量上传文件,包括但不限于mp3,mp4,jpg,txt等文件
'接收二进制表单提交的数据
function requestmyfile()
dim formdata,hcf,fgf,cd,cishu,n,datastart,dataend,datasize,dataLength,temp,d
dim formdatas(29)'29表示数组的最大小标,数组元素个数是最大下标+1=30个
dim tempsz(29,3)
formdata=request.binaryread(request.totalbytes)
hcf=chrB(13)&chrB(10)'回车符
if mynumberb(formdata,hcf)<>0 then
fgf=leftB(formdata,instrb(formdata,hcf)-1)'分隔符
cd=lenb(fgf)'分割符的长度
cishu=mynumberb(formdata,fgf)'分隔符出现的次数
for n=0 to 29
if n+1 = cishu then
exit for
end if
datastart=strnb(n+1,formdata,fgf)+cd
dataend=strnb(n+2,formdata,fgf)-1
datasize=dataend-datastart+1
formdatas(n)=smidb(formdata,datastart,datasize)
temp=stb(formdatas(n),"utf-8")
if instrb(temp,"filename")<>0 then'文件
datastart=strn(1,temp,"""")+1
dataend=strn(2,temp,"""")-1
datasize=dataend-datastart+1
tempsz(n,1)=mid(temp,datastart,datasize)'截取name
datastart=strn(3,temp,"""")+1
dataend=strn(4,temp,"""")-1
datasize=dataend-datastart+1
tempsz(n,2)=mid(temp,datastart,datasize)'截取filename
datastart=strnb(4,formdatas(n),hcf)+2
dataend=strnb(n+2,formdata,fgf)-1
datasize=dataend-datastart+1
tempsz(n,3)=smidb(formdatas(n),datastart,datasize)'截取文件二进制数据
else'文本
datastart=strn(1,temp,"""")+1
dataend=strn(2,temp,"""")-1
datasize=dataend-datastart+1
tempsz(n,1)=mid(temp,datastart,datasize)'截取name
tempsz(n,2)=""'是文本则filename=空值。
datastart=strnb(3,formdatas(n),hcf)+2
dataend=strnb(n+2,formdata,fgf)-1
datasize=dataend-datastart+1
tempsz(n,3)=smidb(formdatas(n),datastart,datasize)'截取文本二进制数据
tempsz(n,3)=stb(tempsz(n,3),"utf-8")'二进制转文本
end if
next
end if
requestmyfile=tempsz
end function
'生成不重复数
function bcfs()
dim a
a=replace(now(),"/","")
a=replace(a," ","")
a=replace(a,":","")
Randomize
bcfs=a&Int((10000 * Rnd) + 1)
end function
'截取二进制流数据
function smidb(data,datastart,datasize)
dim mystream
set mystream = Server.CreateObject("adodb.stream")
mystream.Type = 1'1是二进制,2是文本
mystream.Mode =3'1只读,2只写,3可读写
mystream.Open
mystream.Write data
mystream.position=datastart-1
smidb=mystream.read(datasize)
mystream.close
set mystream=nothing
end function
'二进制保存为文件
sub savefile(mydata,path)
dim mystream
set mystream = Server.CreateObject("adodb.stream")
mystream.Type = 1'1是二进制,2是文本
mystream.Mode =3'1只读,2只写,3可读写
mystream.Open
mystream.Write mydata
mystream.SaveToFile server.mappath(path),2'2表示可以覆盖创建文件
mystream.close
set mystream=nothing
end sub
[此贴子已经被作者于2021-2-25 21:21编辑过]