ASP上传图片并保存到access数据库某个表中的源码,能详细解释一下源码的意思
1个回答
展开全部
给你个例子:
1、access表有以下几个字段:
id 自动编号,
filename 文本,
type 文本,
what OLE对象,
size 数字
2、上传页面(upfile.htm):
文件上传<br />
<form action="upload.asp" method="post" enctype="multipart/form-data">
文件 <input type="file" name="file1" /> <input type="submit" value="上传" />
</form>
3、提交页面(upload.asp):
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--#include file="UpLoad_Class.asp"-->
<%
dim upload
set upload = new AnUpLoad
upload.Exe = "*"
upload.MaxSize = 2 * 1024 * 1024 '2M
upload.charset = "utf-8"
upload.GetData()
if upload.ErrorID>0 then
response.Write upload.Description
else
dim file
for each frm in upload.forms("-1")
response.Write frm & "=" & upload.forms(frm) & "<br />"
next
set file = upload.files("file1")
if not(file is nothing) then
set conn = server.CreateObject("ADODB.connection")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&server.mappath("./")&"\db.mdb"
set rs = server.createobject("adodb.recordset")
rs.Open "pic", conn, 1, 3, 2
rs.addnew
rs.fields("filename") = file.LocalName
rs.fields("type") = file.ContentType
rs.fields("what") = file.GetBytes()
rs.fields("size") = file.Size
rs.update
Response.Redirect "listpic.asp"
end if
end if
set upload = nothing
%>
4、其中引用了UpLoad_Class.asp文件,是艾恩无组件上传类,网上搜一下就能找到。
1、access表有以下几个字段:
id 自动编号,
filename 文本,
type 文本,
what OLE对象,
size 数字
2、上传页面(upfile.htm):
文件上传<br />
<form action="upload.asp" method="post" enctype="multipart/form-data">
文件 <input type="file" name="file1" /> <input type="submit" value="上传" />
</form>
3、提交页面(upload.asp):
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--#include file="UpLoad_Class.asp"-->
<%
dim upload
set upload = new AnUpLoad
upload.Exe = "*"
upload.MaxSize = 2 * 1024 * 1024 '2M
upload.charset = "utf-8"
upload.GetData()
if upload.ErrorID>0 then
response.Write upload.Description
else
dim file
for each frm in upload.forms("-1")
response.Write frm & "=" & upload.forms(frm) & "<br />"
next
set file = upload.files("file1")
if not(file is nothing) then
set conn = server.CreateObject("ADODB.connection")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&server.mappath("./")&"\db.mdb"
set rs = server.createobject("adodb.recordset")
rs.Open "pic", conn, 1, 3, 2
rs.addnew
rs.fields("filename") = file.LocalName
rs.fields("type") = file.ContentType
rs.fields("what") = file.GetBytes()
rs.fields("size") = file.Size
rs.update
Response.Redirect "listpic.asp"
end if
end if
set upload = nothing
%>
4、其中引用了UpLoad_Class.asp文件,是艾恩无组件上传类,网上搜一下就能找到。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询