asp 无组件上传文件名写入数据库问题
我做了个注册页面,该页面可以上传自己照片,现希望上传照片至目录下的同时,将图片路径保存至数据库相关的6个页面:adduser.asp,conn.asp,user_adds...
我做了个注册页面,该页面可以上传自己照片,现希望上传照片至目录下的同时,将图片路径保存至数据库
相关的6个页面:adduser.asp,conn.asp,user_addsave.asp,up.asp,upload.asp,UpLoad_Class.vb
adduser.asp代码
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>注册用户</title>
</head>
<body>
<table>
<form id="form1" name="form1" method="post" action="user_addsave.asp">
<tr height="40">
<td height="30">姓名</td>
<td><input name="name1" type="text" id="name1" /></td>
</tr>
<tr height="40">
<td height="30">性别</td>
<td><input name="sex" type="text" id="sex" /></td>
</tr>
<tr height="40">
<td height="30">年龄</td>
<td><input name="old" type="text" id="old" /></td>
</tr>
<tr height="40">
<td height="30">QQ</td>
<td><input name="qq" type="text" id="qq" /></td>
</tr>
<tr height="40" valign="middle">
<td height="30">照片</td>
<td><iframe scrolling="no" height="45" frameborder="0" marginheight="middle" src="up.asp"></iframe></td>
</tr>
<tr height="40">
<td height="30"> </td>
<td><input type="submit" name="Submit" value="保存" /></td>
</tr>
</form>
</table>
</body>
</html>
up.asp代码
<form action="upload.asp" method="post" enctype="multipart/form-data">
<input type="file" name="file1" /> <input type="submit" value="上传" />
</form>
upload.asp代码
<!--#include file="UpLoad_Class.vbs.asp"-->
<%
dim upload
set upload = new AnUpLoad
upload.Exe = "jpg|bmp|jpeg|gif|png"
upload.MaxSize = 2 * 1024 * 1024 '2M
upload.GetData()
if upload.ErrorID>0 then
response.Write upload.Description
else
dim file,savpath
savepath = "upload"
set file = upload.files("file1")
if not(file is nothing) then
if file.saveToFile(savepath,0,true) then
response.Write ""& savepath & "/" & file.filename &""
else
response.Write file.Exception
end if
end if
end if
set upload = nothing
%>
conn.asp代码
<%
set conn=server.createobject("ADODB.CONNECTION")
connstr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath("cs123.mdb")
conn.open connstr
%>
user_addsave.asp代码
<!--#include file="conn.asp"-->
<!--#include file="upload.asp"-->
<!--#include file="UpLoad_Class.vbs.asp"-->
<%
dim name1,sex,old
name1=trim(request("name1"))
sex=trim(request("sex"))
old=trim(request("old"))
qq=trim(request("qq"))
img=& savepath & "/" & file.filename &
set rs=server.CreateObject("ADODB.RecordSet")
Source="select * from mysf_user"
rs.Open Source,conn,1,3
rs.addnew
rs("name1")=name1
rs("sex")=sex
rs("old")=old
rs("qq")=qq
rs("img")=img
rs.update
response.write "<script>alert('用户添加成功!');window.location.href='user.asp';</script>"
rs.close
set rs=nothing
%>
UpLoad_Class.vbs.asp(该上传类代码没什么问题,因为我单独上传至目录做了测试,限于篇幅不贴出) 展开
相关的6个页面:adduser.asp,conn.asp,user_addsave.asp,up.asp,upload.asp,UpLoad_Class.vb
adduser.asp代码
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>注册用户</title>
</head>
<body>
<table>
<form id="form1" name="form1" method="post" action="user_addsave.asp">
<tr height="40">
<td height="30">姓名</td>
<td><input name="name1" type="text" id="name1" /></td>
</tr>
<tr height="40">
<td height="30">性别</td>
<td><input name="sex" type="text" id="sex" /></td>
</tr>
<tr height="40">
<td height="30">年龄</td>
<td><input name="old" type="text" id="old" /></td>
</tr>
<tr height="40">
<td height="30">QQ</td>
<td><input name="qq" type="text" id="qq" /></td>
</tr>
<tr height="40" valign="middle">
<td height="30">照片</td>
<td><iframe scrolling="no" height="45" frameborder="0" marginheight="middle" src="up.asp"></iframe></td>
</tr>
<tr height="40">
<td height="30"> </td>
<td><input type="submit" name="Submit" value="保存" /></td>
</tr>
</form>
</table>
</body>
</html>
up.asp代码
<form action="upload.asp" method="post" enctype="multipart/form-data">
<input type="file" name="file1" /> <input type="submit" value="上传" />
</form>
upload.asp代码
<!--#include file="UpLoad_Class.vbs.asp"-->
<%
dim upload
set upload = new AnUpLoad
upload.Exe = "jpg|bmp|jpeg|gif|png"
upload.MaxSize = 2 * 1024 * 1024 '2M
upload.GetData()
if upload.ErrorID>0 then
response.Write upload.Description
else
dim file,savpath
savepath = "upload"
set file = upload.files("file1")
if not(file is nothing) then
if file.saveToFile(savepath,0,true) then
response.Write ""& savepath & "/" & file.filename &""
else
response.Write file.Exception
end if
end if
end if
set upload = nothing
%>
conn.asp代码
<%
set conn=server.createobject("ADODB.CONNECTION")
connstr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath("cs123.mdb")
conn.open connstr
%>
user_addsave.asp代码
<!--#include file="conn.asp"-->
<!--#include file="upload.asp"-->
<!--#include file="UpLoad_Class.vbs.asp"-->
<%
dim name1,sex,old
name1=trim(request("name1"))
sex=trim(request("sex"))
old=trim(request("old"))
qq=trim(request("qq"))
img=& savepath & "/" & file.filename &
set rs=server.CreateObject("ADODB.RecordSet")
Source="select * from mysf_user"
rs.Open Source,conn,1,3
rs.addnew
rs("name1")=name1
rs("sex")=sex
rs("old")=old
rs("qq")=qq
rs("img")=img
rs.update
response.write "<script>alert('用户添加成功!');window.location.href='user.asp';</script>"
rs.close
set rs=nothing
%>
UpLoad_Class.vbs.asp(该上传类代码没什么问题,因为我单独上传至目录做了测试,限于篇幅不贴出) 展开
2个回答
展开全部
照片那里加个表单项放地址
<td height="30">照片</td>
<td><iframe scrolling="no" height="45" frameborder="0" marginheight="middle" src="up.asp"></iframe><input type=text name="zp" id="zp"></td>
up.asp代码最后加上
<script>
function backfn(fname){
parent.document.getElementById("zp").value=fname;
}
</script>
upload.asp代码最后加上
<script>window.parent.backfn.apply(this,["<%=file.filename%>"]);</script>
<td height="30">照片</td>
<td><iframe scrolling="no" height="45" frameborder="0" marginheight="middle" src="up.asp"></iframe><input type=text name="zp" id="zp"></td>
up.asp代码最后加上
<script>
function backfn(fname){
parent.document.getElementById("zp").value=fname;
}
</script>
upload.asp代码最后加上
<script>window.parent.backfn.apply(this,["<%=file.filename%>"]);</script>
更多追问追答
追问
按你说的添加了,还是有问题。
追答
传了文件后新增的表单文本框里能获得地址吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询