求如何添加asp代码使图片路径上传到access数据库
有upload.asp,uploadsave.asp,uppic文件夹,数据库名db1.mdb,表:img,用imgpath保存图片路径。图片名已经可以上传到uppic文...
有upload.asp, uploadsave.asp, uppic文件夹,数据库名db1.mdb, 表:img ,用imgpath保存图片路径。图片名已经可以上传到uppic文件夹,求如何添加asp才能使路径上传到数据库。
upload.asp如下:
<body>
form name="form1" method="post" action="uploadsave.asp" enctype="multipart/form-data">
<p align="center"><span style="font-size: 12px">图片上传:</span><br>
<br>
<INPUT type="file" class="f11" name="file1" size="23"><br>
<br>
<input type=submit name="submit" value="上 传" class=anniu >
<br>
<br>
<span style="font-size: 12px">文件格式为<font color="#EC5106">*.gif,*.jpg,*.jpeg
</font>
</span></p>
</form>
</td>
</tr>
</table>
</center>
</body>
uploadsave.asp如下:
<%
set upload=new upload_5xsoft
set file=upload.file("file1")
if file.fileSize>0 then
'自动生成文件名
filename=date()
filename=filename&time()
filename=replace(filename,"-","")
filename=replace(filename,":","")
filename=replace(filename," ","")
filename=filename+"."
filenameend=file.filename
filenameend=split(filenameend,".")
if filenameend(1)="gif" or filenameend(1)="jpg" or filenameend(1)="jpeg" then
filename=filename&filenameend(1)
file.saveAs Server.mappath("uppic/"&filename)
response.write "<p align=center>"
response.write "图片已成功上传至服务器中,请使用下面红色地址添加图片,<br><p align=center><a href=upload.asp>点击这里重新上传图片!</a>"
response.write "</p>"
response.write "<p align=center>"
response.write "<font color=red>"
response.write "asjobcom/uppic/"&filename
response.write "</font></p>"
response.write "<p align=center>"
response.write "<a href='uppic/"&filename&"' target=_blank>点击这里查看上传的图片</a>"
response.write "</p>"
response.write "<p align=center><a href=javascript:window.close()>【关闭窗口】</a>"
else
response.write "文件格式不对"
response.write "<a href=upload.asp>返回"
end if
set file=nothing
else
response.write "文件内容不能为空"
response.write "<a href=upload.asp>返回"
end if
set upload=nothing
response.write "<br>"
%> 展开
upload.asp如下:
<body>
form name="form1" method="post" action="uploadsave.asp" enctype="multipart/form-data">
<p align="center"><span style="font-size: 12px">图片上传:</span><br>
<br>
<INPUT type="file" class="f11" name="file1" size="23"><br>
<br>
<input type=submit name="submit" value="上 传" class=anniu >
<br>
<br>
<span style="font-size: 12px">文件格式为<font color="#EC5106">*.gif,*.jpg,*.jpeg
</font>
</span></p>
</form>
</td>
</tr>
</table>
</center>
</body>
uploadsave.asp如下:
<%
set upload=new upload_5xsoft
set file=upload.file("file1")
if file.fileSize>0 then
'自动生成文件名
filename=date()
filename=filename&time()
filename=replace(filename,"-","")
filename=replace(filename,":","")
filename=replace(filename," ","")
filename=filename+"."
filenameend=file.filename
filenameend=split(filenameend,".")
if filenameend(1)="gif" or filenameend(1)="jpg" or filenameend(1)="jpeg" then
filename=filename&filenameend(1)
file.saveAs Server.mappath("uppic/"&filename)
response.write "<p align=center>"
response.write "图片已成功上传至服务器中,请使用下面红色地址添加图片,<br><p align=center><a href=upload.asp>点击这里重新上传图片!</a>"
response.write "</p>"
response.write "<p align=center>"
response.write "<font color=red>"
response.write "asjobcom/uppic/"&filename
response.write "</font></p>"
response.write "<p align=center>"
response.write "<a href='uppic/"&filename&"' target=_blank>点击这里查看上传的图片</a>"
response.write "</p>"
response.write "<p align=center><a href=javascript:window.close()>【关闭窗口】</a>"
else
response.write "文件格式不对"
response.write "<a href=upload.asp>返回"
end if
set file=nothing
else
response.write "文件内容不能为空"
response.write "<a href=upload.asp>返回"
end if
set upload=nothing
response.write "<br>"
%> 展开
展开全部
在你这句下明没拦面
file.saveAs Server.mappath("uppic/"&filename)察饥
加上激胡
dim conn as new oledb.OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;data source=" & Server.mappath("db1.mdb"))
conn.open
dim sql as string="insert init img (imgpath)values('/uppic/" & filename & "')"
dim cmd as new oledb.OleDbCommand(sql, conn)
cmd.ExecuteNonQuery
cmd.Dispose
.net 是这样用的.应该转成asp也差不多
file.saveAs Server.mappath("uppic/"&filename)察饥
加上激胡
dim conn as new oledb.OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;data source=" & Server.mappath("db1.mdb"))
conn.open
dim sql as string="insert init img (imgpath)values('/uppic/" & filename & "')"
dim cmd as new oledb.OleDbCommand(sql, conn)
cmd.ExecuteNonQuery
cmd.Dispose
.net 是这样用的.应该转成asp也差不多
追问
感谢你的回答,不过出现了问题:不知道哪里出错了。
错误类型:
Microsoft VBScript 编译器错误 (0x800A0401)
语句未结束
/text1/uploadsave.asp, line 32, column 9
dim conn as new oledb.OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;data source=" & Server.mappath("db1.mdb"))
--------^
追答
asp 是语法问题
应该是这样
dim conn,cmd
set conn=server.CreateObject("oledb.OleDbConnection")
conn.ConnectionString="Provider=Microsoft.jet.OLEDB.4.0;data source=" & Server.mappath("db1.mdb")"
conn.open()
set cmd=server.CreateObject("oledb.OleDbCommand")
dim sql
sql="insert init img (imgpath)values('/uppic/" & filename & "')"
cmd.ExecuteNonQuery
cmd.Dispose
cmd.CommandText = sql
cmd.Connection = conn
conn.close()
这样在试一下 ,其实现在.net 比这个强多了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询