请问如何用Asp代码存储图片文件到blob字段?(请修正我的代码)

li5598 2002-09-24 09:09:04
我的代码如下:
a.asp:
<html>
<body>
<center>
   <form name="mainForm" enctype="multipart/form-data"
action="b.asp" method="post">
    <input type=file name=myfile><br>
   <input type=submit name=ok value="确定">
   </form>
</center>
</body>
</html>
b.asp:
<%
set conn=server.createobject("adodb.connection")
conn.Open "aaa","system","manager"

sql2="insert into czgl(blob) values("&request("myfile")&")"
set rs2=conn.execute(sql2)
conn.close

set conn=nothing
%>
错误类型:
请求对象, ASP 0208 (0x80004005)
调用 BinaryRead 后不能使用一般 Request 收集。

我知道肯定不行,可是正确的该如何写?
...全文
63 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
li5598 2002-09-28
  • 打赏
  • 举报
回复
我最后用的方法是上传组件。不过仍感谢瓢兄。
penitent 2002-09-25
  • 打赏
  • 举报
回复
这是我很早时候写asp时候的代码。现在我自己也不一定能看明白,自己仔细看看吧,或许对你有好处,它就可以保存图片到数据库。
'#################################################################
' 上传图片文件
'#################################################################
function checkImageFormat(checkdata)
if flag=0 then
tempstr=Leftb(checkdata,10)
tstr=chrb(255)&chrb(216)&chrb(255)&chrb(224)&chrb(0)&chrb(16)&chrb(74)&chrb(70)&chrb(73)&chrb(70)

if strcomp(tempstr,tstr,0)=0 then
msgstr01="jpg"
lngSize = len(checkdata)
flgFound = 0

strTarget = chrb(255) & chrb(216) & chrb(255)
flgFound = instrb(checkdata, strTarget)

lngPos = flgFound + 2
ExitLoop = false

do while ExitLoop = False and lngPos < lngSize

do while ascb(midb(checkdata, lngPos, 1)) = 255 and lngPos < lngSize
lngPos = lngPos + 1
loop

if ascb(midb(checkdata, lngPos, 1)) < 192 or ascb(midb(checkdata, lngPos, 1)) > 195 then
lngMarkerSize = lngConvert2(midb(checkdata, lngPos + 1, 2))
lngPos = lngPos + lngMarkerSize + 1
else
ExitLoop = True
end if

loop

i_Height = lngConvert2(midb(checkdata, lngPos +4, 2))
i_Width = lngConvert2(midb(checkdata, lngPos +6, 2))
i_Depth = 2 ^ (ascb(midb(checkdata, lngPos + 8, 1)) * 8)

msgstr02=","& i_height & "," & i_width
flag=2
else
flag=0
end if


end if
'--------------------------------------------------check gif--------------------------------
if flag=0 then
tempstr=Leftb(checkdata,6)
tstr=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(57)&chrb(97)
tstr2=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(55)&chrb(97)
if strcomp(tempstr,tstr,0)=0 or strcomp(tempstr,tstr2)=0 then
msgstr03="gif"

i_width=lngConvert(midb(checkdata,7,2))
i_height=lngConvert(midb(checkdata,9,2))
i_Depth = 2 ^ ((ascb(midb(checkdata, 11, 1)) and 7) + 1)
msgstr04=","& i_height & ","& i_width

flag=2
else
flag=0
end if
end if

'---------------------------------------------------check png------------------------------
if flag=0 then
tempstr=Leftb(checkdata,4)
tstr=chrb(137)&chrb(80)&chrb(78)&chrb(71)
if strcomp(tempstr,tstr,0)=0 then
msgstr05="png"

i_Width = lngConvert2(midb(checkdata, 19, 2))
i_Height = lngConvert2(midb(checkdata, 23, 2))
i_Depth = lngConvert(midb(checkdata, 25, 2))

select case ascb(right(i_Depth,1))
case 0
i_Depth = 2 ^ (asc(left(i_Depth, 1)))
gfxSpex = True
case 2
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 3)
gfxSpex = True
case 3
i_Depth = 2 ^ (asc(left(i_Depth, 1))) '8
gfxSpex = True
case 4
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 2)
gfxSpex = True
case 6
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 4)
gfxSpex = True
case else
i_Depth = -1
end select
msgstr06=","& i_height & ","& i_width

flag=2
else
flag=0
end if
end if
if flag=0 then
msgstr07="no image"
end if
msgstr=msgstr01 & msgstr02 & msgstr03 & msgstr04 & msgstr05 & msgstr06 & msgstr07

checkImageFormat=msgstr
end function

function lngConvert2(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
lngConvert2 = clng(ascb(str2) + ((ascb(str1) * 256)))
end function

function lngConvert(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
len1=ascb(str1)
len2=ascb(str2)
lngConvert = clng(ascb(str1) + ascb(str2) * 256)
end function

%>




<%


filesize=Request.totalbytes '客户端响应数据字节的大小
filedata=Request.binaryread(filesize) '得到数据量要小于或等于totalbytes




'*******得到有效的图片的信息*********
bncrlf=chrB(13) & chrB(10)
divider=leftB(filedata,clng(instrB(filedata,bncrlf))-1)
datastart=instrb(filedata,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,filedata,divider)-datastart '(搜索的起点,字符串1,字符串2)
mydata=midb(filedata,datastart,dataend)

arrayMessage=split(checkImageFormat(mydata),",")
'*********************************

%>

<% if arrayMessage(1)>15000 OR arrayMessage(2)>10000 then %>
<script language="javascript">
alert("您所选择的图片的尺寸不符合要求!应在 高*宽 150*100 之间")
window.location="SP.asp"
</script>
<% Else
Set Rs = Server.CreateObject ("ADODB.Recordset")
search="select Siteid from apply where incomedate>=date()-" & neardate & " order by incomedate desc,incometime desc"
dim rs1
set rs1=my_conn.execute(search)
if rs1.bof and rs1.eof then
response.write "数据库中没有记录,不能上传图片"
response.end
end if
Rs.Open "images",My_Conn,3,2
Rs.Addnew
rs("siteId")=rs1("siteid")
Rs.Fields("Newimg").appendchunk mydata
Rs.Update
Rs.Close
search="update apply set newimg=1 where siteid=" & rs1("siteid")
'response.write search
my_conn.execute(search)
rs1.close
set RS=nothing
set rs1=nothing
If Not Err Then
response.write "文件上传成功"

Else
%>
<script language="Javascript">
alert("发生错误!\n错误号为:<%=Err.Number%>\n错误内容:<%=Err.description%>");
</script>
<%
Err.Clear
End If

End if
penitent 2002-09-25
  • 打赏
  • 举报
回复
调用 BinaryRead 后不能使用一般 Request 收集
这是asp的错误,是因为你用了
enctype="multipart/form-data"方式传递数据而又请求
request("myfile")造成的。

图象一般不是这么插入的,需要处理。
insert into czgl(blob) values("&request("myfile")&")"
如定义一个变量,把图象读成二进制的传给这个变量,
你查查csdn吧,我就不给你说了

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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