[求助]asp中图片二进制批量写入access的问题
单个的文件上传好说,用个form,然后再request.totalbytes,就可以了,网上这样的文章也很多,于是也照着做了一个,发现还比较好用,(演示:http://jjk.xt.e21.cn/office/test/)但如果多个图片要上传怎么办呢?
比如一个文件夹里有N多图片,一千张,或者更多,能否有办法在指定文件夹后一次性将图片全部写入数据库?
实在想不出解决办法,请大家赐教! 先谢过了!
代码如下
index.asp
<%Option Explicit%><%
dim rs_lar,rs
dim sql
dim i
dim conn,dbpath
%>
<!--#include file="conn.asp"-->
<%
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from pic"
rs.open sql,conn,3,2
%>
<html>
<script language="javascript">
function mysubmit(theform)
{
if(theform.big.value=="")
{
alert("请点击浏览按钮,选择您要上传的jpg或gif文件!")
theform.big.focus;
return (false);
}
else
{
str= theform.big.value;
strs=str.toLowerCase();
lens=strs.length;
extname=strs.substring(lens-4,lens);
if(extname!=".jpg" && extname!=".gif")
{
alert("请选择jpg或gif文件!");
return (false);
}
}
return (true);
}
</script>
<body>
<center>
<form enctype="multipart/form-data" action="addpic.asp" method=post onsubmit="return mysubmit(this)">
<table border="0" width="50%" cellspacing="0" cellpadding="0">
<tr>
<td width="277"></td>
</tr>
<tr>
<td width="331">
<p align="center">图片地址:<input type="file" name="big" size="20"></p>
</td>
</tr>
<tr>
<td>
<p align="center"></p>
</td>
</tr>
<tr>
<td width="337">
<p align="center"><input type="submit" value="上传" name="B3"> <a href="sendphoto.asp">查看已上传图片</a></p>
</td>
</tr>
</table>
</form>
</body>
</html>
addpic.asp
<%
dim rs
dim formsize,formdata,bncrlf,divider,datastart,dataend,mydata
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)
%>
<!--#include file="conn.asp"-->
<%
sql="select * from pic order by id desc"
set rs=conn.execute(sql)
id=rs("id")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "pic",conn,3,2
rs.addnew
rs("big").appendchunk mydata
rs.update
set rs=nothing
set conn=nothing
response.redirect "sendphoto.asp"
%>
sendphoto.asp
<%Option Explicit%>
<%
dim rs_lar,rs
dim sql,sql1
dim i,id
dim conn,DBPath
%>
<!--#include file="conn.asp"-->
<%
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from pic order by id desc"
rs.open sql,conn,3,2
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片上传</title>
</head>
<body >
<table border="0" width="300" cellspacing="0" cellpadding="0" bgcolor=#FFFFFF height="35">
<% for i=1 to rs.pagesize%>
<%if rs.eof then
exit for
end if
%>
<tr>
<a href="displaypic.asp?id=<%=rs("id")%>"><img src="displaypic.asp?id=<%=rs("id")%>"></a>
</tr>
<%
rs.movenext
next
%>
</table>
<p align="center"><a href="index.asp">返回</a></p>
</body>
</html>
displaypic.asp
<!--#include file="conn.asp"-->
<%
id=request("id")
set rs=server.createobject("ADODB.recordset")
sql="select * from pic where id=" & id
rs.open sql,conn,1,1
Response.ContentType = "image/jpeg"
Response.BinaryWrite rs("big")
rs.close
set rs=nothing
set connGraph=nothing
%>
conn.asp
<%
Set conn = Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("data.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
%>
data.mdb结构:id:自动编号
big:ole对象