日期:2014-05-17  浏览次数:21048 次

怎样在提交表单内容的同时将相应的图片存入数据库,急用!!!
如标题:

    怎样在提交表单内容的同时将相应的图片存入数据库?

------解决方案--------------------
如果要上传到库代码很简单了

asp上传图片2007年03月17日 星期六 10:38一、设计数据库testimg.mdb

为方便调试,设计表imgurl,其中两个字段:id(自动编号、关键字)、img(OLE 对象)

二、连接数据库文件conn.asp


<%
db_path= "testimg.mdb "
set conn=server.CreateObject( "ADODB.connection ")
connstr= "driver={Microsoft Access Driver (*.mdb)};dbq= "&server.MapPath(db_path)
conn.open connstr
%>




三、提供上传图片的表单页面upload.html


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




四、接受数据并添加记录页upload.asp


<!--#include file= "conn.asp "-->
<%
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 imgurl ",conn,3,3
rs.addnew
rs( "img ").AppendChunk myData
rs.update
rs.close
set rs=nothing
set conn=nothing
response.redirect "index.asp "
%>




五、提取数据库表中图片字段内容以做显示图片页showimg.asp


<!--#include file= "conn.asp "-->
<%
set rs=server.createobject( "ADODB.recordset ")
sql= "select * from imgurl where id= "&trim(request( "id "))
rs.open sql,conn,1,1
Response.ContentType= "image/* "
Response.BinaryWrite rs( "img ").getChunk(8000000)
rs.close
set rs=nothing
set conn=nothing
%>




六、显示图片的index.asp


<!--#include file= "conn.asp "-->
<%
strsql= "select * from imgurl "
set rs=server.createobject( "ADODB.recordset ")
rs.open strsql,conn,1,1
do until rs.eof
whatid=rs( "id ")
%>
<img src= "showimg.asp?id= <%=whatid%> ">

<%
rs.movenext
loop%>

建议你别这样做,弄个在线编辑器,或者找个无组建上传的类,把东西存文件夹下就好了。