如何在上传至数据库时提取出图片的格式和长宽(二进制方式)

雅彦 2006-04-26 09:16:43
<%
Response.Buffer=True
formsize=Request.TotalBytes
formdata=Request.BinaryRead(formsize)
bncrlf=chrB(13)&chrB(10)
divider=leftB(formdata,clng(instrb(formdata,bncrlf))-1)
datastart=instrb(formdata,bncrlf&bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
mydata=midb(formdata,datastart,dataend)

set rs=server.createobject("ADODB.recordset")
rs.open "Select * From img Where id is null",conn,1,3
rs.addnew
rs("img").AppendChunk myData
'rs("format")=
'rs("width")=
'rs("height")=
rs("uploadtime")=Now()
rs.update
rs.close
conn.close
set rs=nothing
set conn=nothing
response.redirect "index.asp"
%>
这段代码以二进制方式将图片存入数据库里,希望能同时将图片的格式、长、宽也存入数据库,请问有什么办法;如果不行的话,那么想问在读取数据库里的图片时提取时如何将图片的格式、长、宽提取出来(下面是读取图片的代码<img src="showimg.asp?id=<%=whatid%>" >的showimg.asp页):
<%
Response.Expires = 0
Response.buffer=True
Response.clear
set rs=server.createobject("ADODB.recordset")
sql="select * from img where id="&trim(request("id"))
rs.open sql,conn,1,1
Response.ContentType="image/*"
formsize=rs("img").ActualSize
Response.BinaryWrite rs("img").getChunk(formsize)
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
...全文
195 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
雅彦 2006-04-27
  • 打赏
  • 举报
回复
好像是用form提交过去得二进制数据有无用项,本来的话过就可以用Adodb.Stream取得图像(BMP JPG PNG GIF SWF)并得到它的高度和宽度了,
用formdata二进制流冗余太多,用mydata 二进制图片信息又有缺失,求指导

雅彦 2006-04-27
  • 打赏
  • 举报
回复
还有高手知道马?
雅彦 2006-04-27
  • 打赏
  • 举报
回复
问题已经解决,还是Angel_Heart(天使心) 提供的类看来好用些
Angel_Heart 2006-04-27
  • 打赏
  • 举报
回复
看看这个,应该很有帮助的

http://www.pubcms.com/demo/blog/000463.asp
  • 打赏
  • 举报
回复
我以前改过稻香的无组,你可以根据我写的东西改一下

http://blog.csdn.net/liuxiaoyi666/archive/2004/10/15/137477.aspx
雅彦 2006-04-26
  • 打赏
  • 举报
回复
再顶一下,还有liuxiaoyi666(MSMVP小猪妹马甲之八卦兔子)你的方法怎么和我的代码合在一齐用
雅彦 2006-04-26
  • 打赏
  • 举报
回复
我的上传页是:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>上传图片</title>
</head>

<body>
<form name="form1" action="upload.asp" method="post" enctype="multipart/form-data">
  <input type="file" name="img">
  <input type="submit" name=ok value="ok">
</form>
</body>
</html>


有没有方法取用二进制读取到的图片的格式???
formsize=Request.TotalBytes
formdata=Request.BinaryRead(formsize)
jspadmin 2006-04-26
  • 打赏
  • 举报
回复
http://www.pifoo.com/blog/user1/1/archives/2006/484.shtml
  • 打赏
  • 举报
回复
if InStr (45,sInfo,"filename=""",1) > 0 then
set theFile=new FileInfo
'取得图片长宽
dataend = iformstart-iInfoEnd-1
Image=midb(RequestData,iInfoEnd+1,dataend)
head_height_l = Ascb( midb( Image,165,1 ) )
head_height_h = Ascb( midb( Image,164,1 ) )

head_width_l = Ascb( midb( Image,167,1 ) )
head_width_h = Ascb( midb( Image,166,1 ) )

head_width_h = head_width_h * 256

head_height_h = head_height_h * 256
jpgwidth= head_width_h + head_width_l
jpgheight=head_height_h + head_height_l

28,404

社区成员

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

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