高分求救!!大家帮忙看看这段代码(尤其晓月,因为无组件上传代码就是参考她的),我想在数据库一条记录中上传两个图片。

xiong_r 2002-05-13 06:11:03
大家帮忙看看这段代码(尤其晓月,因为无组件上传代码就是参考她的),我想在数据库一条记录中上传两个图片。
代码如下:
最最让我头疼的页面 subinsert.asp /*试题进入数据库*/
Response.Buffer=TRUE
Response.Clear
ByteCount=Request.TotalBytes
Set Upload=CreateObject("Scripting.Dictionary")
formnum=0
if ByteCount>0 then
BinForm=Request.BinaryRead(ByteCount)
'取出字段分隔串,即形如:-----------------------------7d02a0338e9 的字串
FormID=MidB(BinForm,1,InstrB(BinForm,ChrB(13))-1)
'搜索字段结束串位置,结束串为:-----------------------------7d02a0338e9--
FormEnd=InstrB(1,BinForm,FormID & ChrB(45) & ChrB(45))
BinStart=1 '设置开始串位置为1
'为以下查找作准备
Contentstr=ToBin("Content-Disposition")
Set UpLoadAttrib=CreateObject("Scripting.Dictionary") '定义一个对象存放参数和值
Binbeg=InstrB(BinStart,BinForm,Contentstr) '查找“Content-Disposition”的字串位置
Binbeg=InstrB(Binbeg,BinForm,ToBin("name="))+6 '搜索“name=”字串后跳过“name="表单名"”中第一个引号
Binend=InstrB(Binbeg,BinForm,ChrB(34)) '搜索“name="表单名"”中最后一个引号
FormName=Tostr(MidB(BinForm,Binbeg,BinEnd-BinBeg)) '取出表单名
BinStart=BinEnd+1 '设置下一个搜索指针
Binbeg=InstrB(BinStart,BinForm,ToBin("name=")) '搜索“filename=”字串以判断是否是File类型表单
Binend=InstrB(BinStart,BinForm,FormID) '搜索下一个字段分隔符以确定上一个搜索是否是File表单内容
if BinBeg<>0 and Binbeg<BinEnd then '判断“filename=”字串是否存在,且在本表单范围内
Binstart=Binbeg+10 '跳过“filename="文件名"”在第一个引号
BinEnd=InstrB(BinStart,BinForm,ChrB(34)) '搜索“filename="文件名"”中最后一个引号
UploadFileName=Lcase(Tostr(MidB(BinForm,BinStart,BinEnd-BinStart))) '取文件名
Binbeg=InstrB(BinEnd,BinForm,ToBin("Content-Type:"))+14 '搜索“Content-Type:”字串,并跳过它
BinEnd=InstrB(Binbeg,BinForm,ChrB(13)) '搜索回车符以确定文件类型串的长度
UpLoadType=ToStr(MidB(BinForm,Binbeg,BinEnd-Binbeg)) '取出文件类型串
Binbeg=BinEnd+4 '跳过“0D 0A 0D 0A”指向表单值的开始位置
BinEnd=InstrB(BinBeg,BinForm,FormID)-2 '搜索下一个字段开始位置,并后退“0D 0A”两位,以指向表单值结束位置
FileSize=BinEnd-BinBeg '求出值的长度
if FileSize>30000 then '判断值的长度是否超过最大长度
FileSize=-1 '如果超过,则设长度为-1
Value=""
elseif FileSize<1 then
FileSize=0
Value=""
else
Value=MidB(BinForm,BinBeg,FileSize) '取出值
end if
formnum=formnum+1
Else
BinBeg=InstrB(BinStart,BinForm,ChrB(13))+4 '确定非文件类型表单的值的开始位置
BinEnd=InstrB(BinBeg,BinForm,FormID)-2 '确定结束位置
FileSize=BinEnd-BinBeg '求出值的长度
Value=ToStr(MidB(BinForm,BinBeg,FileSize)) '取出值并转化为标准字串
UpLoadType="Text" '定义保存类型为“Text”
UpLoadFileName=FormName '设置文件名为表单名
End if
'将取出数据存入对象中
UpLoadAttrib.Add "subgraph",Value
UpLoadAttrib.Add "subgraphtype",UploadType
UpLoadAttrib.Add "subgraphname",UploadFileName
UpLoad.Add FormName,UploadAttrib
set UploadAttrib=nothing
BinStart=BinEnd+2 '指向下一个字段开始处
Set UpLoadAttrib=CreateObject("Scripting.Dictionary")
Binbeg=InstrB(BinStart,BinForm,Contentstr)
Binbeg=InstrB(Binbeg,BinForm,ToBin("name="))+6
Binend=InstrB(Binbeg,BinForm,ChrB(34))
FormName=Tostr(MidB(BinForm,Binbeg,BinEnd-BinBeg))
BinStart=BinEnd+1 '设置下一个搜索指针
Binbeg=InstrB(BinStart,BinForm,ToBin("name="))
Binend=InstrB(BinStart,BinForm,FormID)
if BinBeg<>0 and Binbeg<BinEnd then
Binstart=Binbeg+10
BinEnd=InstrB(BinStart,BinForm,ChrB(34))
UploadFileName=Lcase(Tostr(MidB(BinForm,BinStart,BinEnd-BinStart)))
Binbeg=InstrB(BinEnd,BinForm,ToBin("Content-Type:"))+14
BinEnd=InstrB(Binbeg,BinForm,ChrB(13))
UpLoadType=ToStr(MidB(BinForm,Binbeg,BinEnd-Binbeg))
Binbeg=BinEnd+4
BinEnd=InstrB(BinBeg,BinForm,FormID)-2
FileSize=BinEnd-BinBeg
if FileSize>30000 then
FileSize=-1
Value=""
elseif FileSize<1 then
FileSize=0
Value=""
else
Value=MidB(BinForm,BinBeg,FileSize)
end if
formnum=formnum+1
Else
BinBeg=InstrB(BinStart,BinForm,ChrB(13))+4
BinEnd=InstrB(BinBeg,BinForm,FormID)-2
FileSize=BinEnd-BinBeg '求出值的长度
Value=ToStr(MidB(BinForm,BinBeg,FileSize))
UpLoadType="Text"
UpLoadFileName=FormName
End if
'将取出数据存入对象中
UpLoadAttrib.Add "ansgraph",Value
UpLoadAttrib.Add "ansgraphtype",UploadType
UpLoadAttrib.Add "ansgraphname",UploadFileName
UpLoad.Add FormName,UploadAttrib
set UploadAttrib=nothing
End if

errs=""
if formnum=0 then
errs="没有上传图片"
Set conn=Server.CreateObject("ADODB.Connection")
DbPath = Server.mapPath("paper.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DbPath
Set rs=Server.Createobject("ADODB.Recordset")
subtype=Upload.Item("subtype").Item("Value")
chapterid=Upload.Item("chapterid").Item("Value")
sectionid=Upload.Item("sectionid").Item("Value")
difficulty=Upload.Item("difficulty").Item("Value")
subtime=Upload.Item("subtime").Item("Value")
subscore=Upload.Item("subscore").Item("Value")
submatter=Upload.Item("submatter").Item("Value")
if (subtype=1 or subtype=2) then
xzanswer=Upload.Item("xzanswer").Item("Value")
select1=Upload.Item("select1").Item("Value")
select2=Upload.Item("select2").Item("Value")
select3=Upload.Item("select3").Item("Value")
select4=Upload.Item("select4").Item("Value")
end if
if subtype=2 then
select5=Upload.Item("select5").Item("Value")
select6=Upload.Item("select6").Item("Value")
end if
if subtype=3 then
tkanswer=Upload.Item("tkanswer").Item("Value")
end if
if subtype=4 then
jdanswer=Upload.Item("jdanswer").Item("Value")
end if
f=Upload.Keys
judge=0
subject=0
answer=0
for i=0 to upload.count-1
mime=Upload.Item(f(i)).Item("Type")
if mime="file" then
if judge=0 then
judge=1
subject=i
name=Upload.Item(f(i)).Item("FileName")
temp=instrRev(name,"\")
subname=mid(name,temp+1)
subtyp=getType(mime)
else
answer=i
name=Upload.Item(f(i)).Item("FileName")
temp=instrRev(name,"\")
ansname=mid(name,temp+1)
anstyp=getType(mime)
end if
end if
next
rs.Open "Select * From subject" ,conn,1,3
rs.addnew
if subject<>0 then
rs("subgraph").AppendChunk Upload.Item(f(subject)).Item("Value")
rs("subgraphname") =subname
rs("subgraphtype")=subtyp
end if
if answer<>0 then
rs("ansgraph").AppendChunk Upload.Item(f(answer)).Item("Value")
rs("ansgraphname") =ansname
rs("ansgraphtype")=anstyp
end if
rs("userName")=replace(username,"'","''")
rs("subtype")=replace(subtype,"'","''")
rs("chapterid")=replace(chapterid,"'","''")
rs("sectionid")=replace(sectionid,"'","''")
rs("difficulty")=replace(difficulty,"'","''")
rs("subtime")=replace(subtime,"'","''")
rs("subscore")=replace(subscore,"'","''")
rs("submatter")=replace(submatter,"'","''")
if (subtype=1 or subtype=2) then
rs("xzanswer")=replace(xzanswer,"'","''")
rs("select1")=replace(select1,"'","''")
rs("select2")=replace(select2,"'","''")
rs("select3")=replace(select3,"'","''")
rs("select4")=replace(select4,"'","''")
end if
if subtype=2 then
rs("select5")=replace(select5,"'","''")
rs("select6")=replace(select6,"'","''")
end if
if subtype=3 then
rs("tkanswer")=replace(tkanswer,"'","''")
end if
if subtype=4 then
rs("jdanswer")=replace(jdanswer,"'","''")
end if
rs.Update
errs=errs & "<br>" & name & "试题已成功进入数据库。"
rs.close
conn.close
set rs=nothing
set conn=nothing
end if
%>

</body>

</html>
...全文
38 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ssm1226 2002-05-14
  • 打赏
  • 举报
回复
搜索搜索,好像很多哦


★★★一起去淋雨★★★

ChinaOk 2002-05-14
  • 打赏
  • 举报
回复
http://www.chinaok.net/down/LostinetUpload_1_03.zip
xiong_r 2002-05-14
  • 打赏
  • 举报
回复
但我上不了这个网站,总是连接超时,能不能另给一个,100分一定给!!
ChinaOk 2002-05-13
  • 打赏
  • 举报
回复
http://lostinet.d2g.com

有传到数据库里的。还可以选择数量

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧