asp下载数据库access中图片

whoo529 2008-10-19 10:17:34
现在有一asp程序,需要下载access中图片[二进制]
<a title="下载图片" href="../image.asp?id=<%=id%>" target="_blank">这样可以下载,但格式为.asp,下载来后修改为.jpg也可以显示正常图片,这个方法显然不正确;首先创建jpg文件,将数据库中二进制图片读取出来写入创建的jpg文件即可

代码块:
fileimage = rs("image")

set fileobject=server.CreateObject ("scripting.filesystemobject")
set out = fileobject.CreateTextFile (Server.MapPath("image.jpg"),true,false)
out.write fileimage '此处有问题,不能写入此类型文件
set out = nothing

问题在于如何写入此二进制数据到image.jpg中,请教各位
...全文
261 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
sklovexj 2008-12-09
  • 打赏
  • 举报
回复
谢谢分享

www.tom3gp.com
  • 打赏
  • 举报
回复
呵呵,简单吧

不再觉得难了?
whoo529 2008-10-20
  • 打赏
  • 举报
回复
贴出代码:
<%
fileimage = rs("image")
imgs=fileimage
Set objStream = Server.CreateObject("ADODB.Stream")
with objStream
.Type =1
.Open
'.write imgs.getChunk(imgs.actualSize)
.write imgs
.SaveToFile server.mappath("image.jpg"),2
.Close()
end with
set objstream=nothing
%>
<a href="down.asp?filename=image.jpg" target="_blank">
<img border="0" src="images/xz.gif" width="55" height="18"></a>
-------------------------------------------------------------------------
down.asp:
<% strFile=Trim(Request.QueryString("filename"))
if strFile="" or isnull(strFile) then
Response.Write("<h1>缺少参数</h1>")
Response.End
end if
strFilename = server.MapPath(strFile)
Response.Buffer = True
Response.Clear
Set s = Server.CreateObject("ADODB.Stream")
s.Open
s.Type = 1
on error resume next
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:" & strFilename & " 文件不存在</h1>")
Response.End
end if
Set f = fso.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error:" & err.Description & " </h1>")
Response.End
end if
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite s.Read
Response.Flush
s.Close
Set s = Nothing
%>
  • 打赏
  • 举报
回复
............
whoo529 2008-10-20
  • 打赏
  • 举报
回复
貌似解决了
whoo529 2008-10-20
  • 打赏
  • 举报
回复
问题来了,ADODB.Stream 错误 '800a0bbc'

google以后说是权限问题,我加了everyone 、iuser_computername 所有权限都”写入文件失败“
这是什么问题呢?
peipei160509 2008-10-20
  • 打赏
  • 举报
回复
down.asp:
<% strFile=Trim(Request.QueryString("filename"))
if strFile="" or isnull(strFile) then
Response.Write(" <h1>缺少参数 </h1>")
Response.End
end if
strFilename = server.MapPath(strFile)
Response.Buffer = True
Response.Clear
Set s = Server.CreateObject("ADODB.Stream")
s.Open
s.Type = 1
on error resume next
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write(" <h1>Error:" & strFilename & " 文件不存在 </h1>")
Response.End
end if
Set f = fso.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
if err then
Response.Write(" <h1>Error:" & err.Description & " </h1>")
Response.End
end if
Response.AddHeader "Content-Disposition", "www.ebuir.com"& f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite s.Read
Response.Flush
s.Close
Set s = Nothing
%>
whoo529 2008-10-19
  • 打赏
  • 举报
回复
不是啊,我在网吧里做的,这里没有iis,我只有把做好的东西直接传人服务器,回去了在调试
家里网络极差

这样应该能行吧,谢谢各位
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 whoo529 的回复:]
服务器显示没有权限写入,我回去了在试试看
[/Quote]

.......你都没有权限,你还搞什么啊!!
sy_binbin 2008-10-19
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 chinmo 的回复:]
imgs=imagefile'取得图片的具休内容
Set objStream = Server.CreateObject("ADODB.Stream")'建立ADODB.Stream对象,必须要ADO 2.5以上版本
with objStream
.Type =1'以二进制模式打开
.Open
.write imgs'将字符串内容写入缓冲
.SaveToFile server.mappath("image.jpg"),2'-将缓冲的内容写入文件
.Close()
end with
set objstream=nothing
试试这个方法
[/Quote]

这个方法可以写文件

但服务器要是没权限那就没啥办法了
whoo529 2008-10-19
  • 打赏
  • 举报
回复
服务器显示没有权限写入,我回去了在试试看
epui2008 2008-10-19
  • 打赏
  • 举报
回复
第一次听说,关注下,学习学习
sy_binbin 2008-10-19
  • 打赏
  • 举报
回复
搞不明白为什么要把图片保存在数据库里呢???
  • 打赏
  • 举报
回复
imgs=imagefile'取得图片的具休内容
Set objStream = Server.CreateObject("ADODB.Stream")'建立ADODB.Stream对象,必须要ADO 2.5以上版本
with objStream
.Type =1'以二进制模式打开
.Open
.write imgs'将字符串内容写入缓冲
.SaveToFile server.mappath("image.jpg"),2'-将缓冲的内容写入文件
.Close()
end with
set objstream=nothing
试试这个方法
  • 打赏
  • 举报
回复
ADODB.Stream
你要写进文件?可以用他啊!他有一个二进制的写法啊
whoo529 2008-10-19
  • 打赏
  • 举报
回复
这样的话还是显示在页面上了,需要创建jpg文件到服务器才能下载
  • 打赏
  • 举报
回复
Response.ContentType = "image/*"

Response.BinaryWrite imagefile.getChunk(7500000)
  • 打赏
  • 举报
回复
Response.ContentType = "image/*"

Response.BinaryWrite imagefile.getChunk(7500000)
whoo529 2008-10-19
  • 打赏
  • 举报
回复
加上上面的那段是打印出来需要的,现在我要将此二进制写入jpg,能否告知如何操作
  • 打赏
  • 举报
回复
Response.ContentType = "image/gif "
如果是图片的还得加上类似这样的
加载更多回复(5)
ASP.NET留言板 Version 1.0 软件信息: 软件名称:光辉岁月留言板 版 本 号:Version 1.0 授权类型:免费软件 运行环境:ASP.NET 版权所有:光辉岁月 Q Q:258653163 开发日期:2007.1 软件描述: 1、使用ASP.NET(C#)开发; 2、全部代码都由手写完成,清晰易懂、易维护; 3、采用三层体系结构,通过接口继承来支持多数据库模式; 4、动态支持Access,MSSQL(存储过程); 5、支持HTML编辑器,集成QQ,MSN,TAOBAO等表情; 版权声明: 1. 本软件由本人独立开发完成的留言平台,拥有留言簿的所有版权。 2. 本软件为免费软件,授权用户免费使用,无须通告作者本人。 3. 允许任何人可以在本软件的基础上独立开发新的模块,并可自由商业或免费,并不受限制。 4. 本软件使用了部分网络上的资源(包括图像,皮肤等)。如果您有任何意见或想法可以与我取得联系 。我将会根据您的意愿进行修改。 免责声明: 1.本软件是免费软件,作者只负责软件本身的制作与维护,不负责任何与软件本身无关的问题。 2.用户自愿使用本软件,并无须支付任何费用,由使用软件对用户所造成的任何损失均与作者无关。 3.用户在使用本软件时所引起的任何纠纷均与作者无关。 4.浏览者发表的任何言论,纯属浏览者个人意见,概与作者无关。 5.用户使用本软件,即表示无条件接受以上条款。 6.作者保留以上条款的最终解释权。 安装使用: Access环境 前提必须支持asp.net 注意:你电脑的系统必须装了Internet 服务管理器和Microsoft.NET Framework 1.1或2.0 双击Setup.exe应用文件,然后进行安装。然后进入C:\\Inetpub\\wwwroot\\BBS里面的#chat.mdb数据拿出来 到C:\\ 数据库的路径可以在Web.config里面的以下改: 最后就可以在IE里面的地址栏上输入http://localhost/bbs运行出来了。 ****************************************************************************************** 注意:请不要直接进入数据库更改密码,因为数据库已经通过MD5的数据加过密,要更改密码,请用默认 的系统管理员帐号和密码登录,进去可以更改,要是你直接进数据库自己改的会,可能会出现不能登录的 问题。 ****************************************************************************************** 默认系统管理员帐号:admin 默认系统管理员密码:admin 常见问题: 如果出现未设置对象实例,无法添加记录,DBNULL转换失败等错误,可能是数据库遭到破坏,如果是NTFS分区 ,最好将数据库文件的EVERYONE用户的所有权限设置为允许 与我联系: QQ:258653163 官方主页: http://www.ghsy123.com 电子邮件: pyh123@126.com 2007.2

28,392

社区成员

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

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