Everyday NetLog

快捷导航
专栏分类
zhoz blog 重新开张,欢迎继续支持!
Oct 14

直接在ACCESS数据库中直接储存图片 多云

前面有人写过PHP储存图片的内容,刚泡完澡,写个以前关于ASP上传直接存到库的来完结今天。
前提情况说明:

表:table 存储字段:photo、类型(OLE 对象)
读图程序:show_photo.asp


1、上传图片

       <table border="0" width="100%" cellpadding="0">                                    
        <tr>                                    
          <td width="74%" nowrap>上传新照片:<input type="file" name="photo"></td>                                  
          <td width="26%">                                
            <p align="right"><input type=submit value="上传照片"></p>                                
          </td>                                
        </tr>                                
      </table>



2、储存到库方法

<!--#include file="conn.asp"-->
<%
set rs=server.createobject("adodb.recordset")            
sql="select * from table where user='"&request("user")&"'"            
rs.open sql,conn,1,3                  
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                  
photodata=midb(formdata,datastart,dataend)            
rs("photo").appendchunk photodata            
rs.update            
rs.close            
set rs=Nothing
%>            


3、删除方法
rs("photo")=Null

4、ASP读取的方法
<img src="show_photo.asp?id=<%=id%>">

show_photo.asp代码:

<!--#include file="conn.asp"-->
<%
Set rs=Server.CreateObject("ADODB.recordset")
sql="select photo from table where id=" & request("id")
rs.open sql,conn,1,1
Response.ContentType = "image/*"
Response.BinaryWrite rs("photo").getChunk(7500000)
rs.close
set rs=nothing
conn.close
set conn=nothing
end If
%>



以上几步,完成了各种操作了。慢慢理解一下,相应有收获。脖子有点痛了,我得去活动活动了。。。
作者:zhoz
出处:Everyday NetLog(转载请注明出处)
Tags:
👤 applehan Email
2007/11/30 15:56
我按您提供的代码试了一下,出了以下错误提示,请教如何解决?

Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e10'

[Microsoft][ODBC Microsoft Access Driver] 参数不足,期待是 1。

/new/Save_Photo.asp,行 5

行5:rs.open sql,conn,1,3
💬 zhoz 回复于 2007/12/01 09:44
抱歉,这个文件中也要包含连库文件<!--#include file="conn.asp"-->请修正吧。
👤 Applehan
2007/11/28 13:42
请问conn.asp在哪里?
💬 zhoz 回复于 2007/11/29 11:26
这个就是常用的连接库的文件了,这里省略了没有注明。我单独开一个帖子来说明,常用的库连接文件吧。敬请关注。
http://log.zhoz.com/read.php?101
分页: 1/1 第一页 1 最后页
✍ 发表评论

[注册]

  (快捷键:Ctrl + Enter 快速提交)