<%
'查询二进制数据流str2在str1里面出现的次数。
function mynumberb(str1,str2)
dim mystart,myend,cishu
cishu=0
mystart=instrb(str1,str2)
if mystart>0 then
cishu=cishu+1
myend = instrb(mystart+lenb(str2),str1,str2)
do while myend>0
cishu=cishu+1
myend=instrb(myend+lenb(str2),str1,str2)
loop
end if
mynumberb=cishu
end function
'查询二进制数据流str2在str1里面第N次出现的位置,如果没有出现,返回0。
function strNb(N,str1,str2)
dim mystart,myend,cishu
cishu=0
mystart=instrb(str1,str2)
if mystart>0 then
cishu=cishu+1
if cishu=N then
strNb=mystart
exit function
end if
myend=instrb(mystart+lenb(str2),str1,str2)
do while myend>0
cishu=cishu+1
if cishu=N then
strNb=myend
exit function
end if
myend=instrb(myend+lenb(str2),str1,str2)
loop
else
strNb=0
end if
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
'二进制转字符
Function stb(vin,bm)
Const adTypeText=2
Dim BytesStream,StringReturn
Set BytesStream=Server.CreateObject("ADODB.Stream")
With BytesStream
.Type = adTypeText
.Open
.WriteText vin
.Position=0
.Charset=bm
.Position = 2
StringReturn = .ReadText
.Close
End With
Set BytesStream=Nothing
stb=StringReturn
End Function
'查询字符串str2在字符串str1里面第N次出现的位置,如果没有出现,返回空。
function strN(N,str1,str2)
dim temp
dim s
dim datastart
dim cishu
temp=1
for s=1 to len(str1)
datastart=instr(temp,str1,str2)
if datastart=0 or datastart=null then
exit for
end if
if datastart<>0 or datastart<>null then
temp=datastart+len(str2)
cishu=cishu+1
if cishu=N then
strN=datastart
exit for
end if
end if
next
if cishu<N then
strN=""
end if
end function
'二进制保存为文件
sub savetofile(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
'接收二进制表单提交的数据
sub requestmyfile()
dim formdata,hcf,fgf,cd,cishu,n,datastart,dataend,datasize,dataLength,temp,formdatas
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)'分隔符出现的次数
dim tempsz()
redim tempsz(cishu-2,2)
for n=0 to cishu-2
datastart=strnb(n+1,formdata,fgf)+cd
dataend=strnb(n+2,formdata,fgf)-1
datasize=dataend-datastart+1
formdatas=smidb(formdata,datastart,datasize)
temp=stb(formdatas,"utf-8")
if instrb(temp,"filename=")<>0 then'文件
datastart=strn(1,temp,"""")+1
dataend=strn(2,temp,"""")-1
datasize=dataend-datastart+1
tempsz(n,0)=mid(temp,datastart,datasize)'截取name
datastart=strn(3,temp,"""")+1
dataend=strn(4,temp,"""")-1
datasize=dataend-datastart+1
tempsz(n,1)=mid(temp,datastart,datasize)'截取filename
execute "file_"&tempsz(n,0)&"_name="&""""&tempsz(n,1)&""""
datastart=strnb(4,formdatas,hcf)+2
dataend=strnb(n+2,formdata,fgf)-1
datasize=dataend-datastart+1
tempsz(n,2)=smidb(formdatas,datastart,datasize)'截取文件二进制数据
execute "file_"&tempsz(n,0)&"_file=smidb(formdatas,datastart,datasize)"
execute "file_"&tempsz(n,0)&"_size="&lenb(tempsz(n,2))
else'文本
datastart=strn(1,temp,"""")+1
dataend=strn(2,temp,"""")-1
datasize=dataend-datastart+1
tempsz(n,0)=mid(temp,datastart,datasize)'截取name
datastart=strnb(3,formdatas,hcf)+2
dataend=strnb(n+2,formdata,fgf)-1
datasize=dataend-datastart+1
tempsz(n,2)=smidb(formdatas,datastart,datasize)'截取文本二进制数据
tempsz(n,2)=stb(tempsz(n,2),"utf-8")'二进制转文本
tempsz(n,2)=left(tempsz(n,2),len(tempsz(n,2))-2)'去掉最后的一个换行符号
tempsz(n,2)=replace(tempsz(n,2),vbcrlf,"$我的华丽的回车换行符号哦哦哦$")
tempsz(n,2)=replace(tempsz(n,2),"""","""""")
execute "text_"&tempsz(n,0)&"_value="&""""&tempsz(n,2)&""""
execute "text_"&tempsz(n,0)&"_value=replace(text_"&tempsz(n,0)&"_value,""$我的华丽的回车换行符号哦哦哦$"",vbcrlf)"
end if
next
end if
end sub
if request.totalbytes > 0 then
call requestmyfile()
call savetofile(file_mypic_file,file_mypic_name)
response.write "<script>alert('ok');self.location=document.referrer;</script>"
response.end
end if
'说明
'file_filename_file:文件二进制数据
'file_filename_name:文件名,可以从文件名继续获得扩展名
'此上传组件没有文件长度size,完全可以用lenb()得到文件二进制数据的长度,间接计算出文件大小。
'上传的就是文件了,不需要access,path是保存的路径,自己设置。
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>上传图片到access</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/pc.css" charset="utf-8">
<meta name="viewport" content="width=10,initial-scale=1,user-scalable=no">
<meta name="applicable-device" content="pc,mobile">
<style>
form{
margin-top:20px;
margin-left:20px;
}
</style>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input type="file" name="mypic">
<input type="submit" name="sc" value="上传">
</form>
</body>
</html>
2021年06月07日 01点06分
4