关于图片上传问题

lwc92008 2003-10-16 05:48:55
大家看看这段代码有没有什么错误,我上传了一张较大的图片,也就55K,500*500的图片,但只能显示到大约500*400的地方也就没影了。这是怎么回事,呵以下是代码,大家帮忙看看有什么错误。
<%
dim cnstr
cnstr = "driver={Microsoft Access Driver (*.mdb)};dbq=" & server.MapPath("./upload.mdb")
%>
<HTML>
<HEAD>
<title>单个图像保存到数据库</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<body>
<p><a href="SimpleImageToData.asp">上传图片</a>
<a href="ShowImageListFromData.asp">显示图片</a><hr></p>

<%
if request.ServerVariables("REQUEST_METHOD") = "POST" then
dim sCome, sGo, binData, strData
dim posB, posE, posSB, posSE
dim binCrlf
dim strPath, strFileName, strContentType
if request.TotalBytes<102400 then
binCrlf = chrb(13)&chrb(10)
set sCome = server.CreateObject("adodb.stream")
sCome.Type = 1 '指定返回数据类型 adTypeBinary=1,adTypeText=2
sCome.Mode = 3 '指定打开模式 adModeRead=1,adModeWrite=2,adModeReadWrite=3
sCome.Open
sCome.Write request.BinaryRead(request.totalbytes)

sCome.Position = 0
binData = sCome.Read
set sGo = server.CreateObject("adodb.stream")
sGo.Type = 1
sGo.Mode = 3
sGo.Open

posB = 1
posB = instrb(posB,binData,binCrlf)
posE = instrb(posB+1,binData,binCrlf)
sCome.Position = posB+1
sCome.CopyTo sGo,posE-posB-2
sGo.Position = 0
sGo.Type = 2
sGo.Charset = "gb2312"
strData = sGo.ReadText
sGo.Close

posSB = 1
posSB = instr(posSB,strData,"filename=""") + len("filename=""")
posSE = instr(posSB,strData,"""")
x=instrRev(strData,".")
huo=Lcase(mid(strData,x+1,3))
if huo="gif" or huo="jpg" then
if posSE > posSB then
strPath = mid(strData,posSB,posSE-posSB)
posB = posE
posE = instrb(posB+1,binData,binCrlf)
sGo.Type = 1
sGo.Mode = 3
sGo.Open

sCome.Position = posB
sCome.CopyTo sGo,posE-posB-1

sGo.Position = 0
sGo.Type = 2
sGo.Charset = "gb2312"
strData = sGo.ReadText
sGo.Close
strContentType = mid(strData,16)
posB = posE+2
posE = instrb(posB+1,binData,binCrlf)
sGo.Type = 1
sGo.Mode = 3
sGo.Open

sCome.Position = posB+1
sCome.CopyTo sGo,posE-posB-2

sGo.Position = 0
strData = sGo.Read
sGo.Close
dim cn, rs, sql
set cn = server.CreateObject("adodb.connection")
cn.Open cnstr
set rs = server.CreateObject("adodb.recordset")
sql = "select * from tblImage"
rs.Open sql,cn,1,3
rs.AddNew
rs.Fields("content-type").Value = strContentType
rs.Fields("image").AppendChunk strData
rs.Update
rs.Close
set rs = nothing
cn.Close
set cn = nothing
response.Write "图片保存成功!" & "<br>"
else
response.Write "没有上传图片!" & "<br>"
end if
else
response.write "图片格式应为jpg或gif"
end if
set sGo = nothing
sCome.Close
set sCome = nothing
else
response.write "文件大小应小于100K"
end if
else
%>
<form id="frmUpload" name="frmUpload" action="SimpleImageToData.asp" method="post" target="_self" enctype="multipart/form-data">
<INPUT id="filImage" type="file" name="filImage" size="40">
<BR>
<INPUT id="btnUpload" type="submit" value="Upload" name="btnUpload">
</form>
<%
end if
%>
</body>
</HTML>

...全文
29 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lwc92008 2003-10-16
  • 打赏
  • 举报
回复
呵,这段代码就是参考别人的,(应该说是COPY过来的,)
NetBoy 2003-10-16
  • 打赏
  • 举报
回复
再写一遍吧,代码太长了,别人半天还看不明白,要么自己找,要么找个别人参考一下,对比,找找哪儿不合适

28,390

社区成员

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

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