关于使用无惧上传的一个问题,请兄弟们帮帮忙!!
小弟使用无惧上传做后台(直接把图片添加到数据库中的),就是通过后台添加记录,记录的字段有图片显示还有一些文字介绍等等,小弟第一次用无惧,是不是先把图片添加到数据库中然后在把文字添加到数据库中?我这样做就出现问题了,因为添完图片后就新添加了一个记录,我接着再添加文字,怎么让文字直接添加到刚才上传图片的这个记录中呢??
能不能文字和图片直接一起添加那样最好了可是我弄了半天弄不懂啊?
大家帮我看看这两个方法好吗??
在upfiletodb.asp中:
<%OPTION EXPLICIT%><html>
<head>
<style type="text/css">
<!--
.p9{ font-size: 9pt; font-family: 宋体 }
td {font-size: 9pt}
.tx {height: 16px; width: 30px; border-color: black black #000000; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; font-size: 9pt; background-color: #eeeeee; color: #0000FF}
.tx2 {height: 16px;border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; font-size: 9pt; color: #0000FF; border-left-color:#000000; border-right-color:#000000; border-top-color:#000000; border-bottom-color:#000000}
.bt {border-left:1px solid #C0C0C0; border-top:1px solid #C0C0C0; font-size: 9pt; border-right-width: 1; border-bottom-width: 1; height: 16px; width: 80px; background-color: #EEEEEE; cursor: hand; border-right-style:solid; border-bottom-style:solid}
.tx1 { width: 400 ;height: 20px; font-size: 9pt; border: 1px solid; border-color: black black #000000; color: #0000FF}
-->
</style>
<title>无惧上传类</title>
</head>
<body bgcolor="#ffffff" class="p9" onload="addfile()">
<form method="post" name="form1" action="savetodb.asp" enctype="multipart/form-data">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="750" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#111111" style="BORDER-COLLAPSE: collapse">
<tr>
<td height="23" colspan="2" valign="bottom"> <div align="center">
<input type="file" name="file">
</div></td>
</tr>
<tr>
<td height="23" colspan="2" valign="bottom"><div align="center">文件名:
<input name="username" type="text" id="username2" size="15" maxlength="15">
文件类型:
<input name="busiclass" type="text" id="busiclass2" size="15" maxlength="15">
</div></td>
</tr>
<tr>
<td height="30" colspan="2" align="middle"> <div align="center">
<input type="submit" name="Button" class="bt" value="上 传">
<input type="reset" name="Button" class="bt" value="重 置">
</div></td>
</tr>
</table></td>
</tr>
</table>
</form>
<table align="center" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" class="p9" style="border-collapse: collapse">
<tr bgcolor="#CCCCCC">
<td width="84" height="25" valign='middle'> 原文件路径 </td>
<td width="84" valign='middle'> 大小(字节) </td>
<td width="72" valign='middle'> 保存名称 </td>
<td width="27" valign='middle'> 操作 </td>
</tr>
<%
dim conn,rs,i,ServerPath
conn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("dbase.mdb")
set rs=Server.CreateObject("adodb.recordset")
rs.Open "select * from FileInfo",conn,1,3
if not (rs.BOF and rs.EOF) then
ServerPath=GetFilePath(Request.ServerVariables("HTTP_REFERER"),"/")'取得在网站上的位置
for i=1 to rs.RecordCount
%>
<tr>
<td height="20" valign='middle'> <%=rs("FilePath")%> </td>
<td valign='middle'> <%=rs("filesize")%> </td>
<td valign='middle'> <A HREF="<%=serverpath&"readdbfile.asp?filename="&rs("FileName")%>"><%=rs("FileName")%></A> </td>
<td valign='middle'> <A HREF="<%=serverpath&"deldbfile.asp?filename="&rs("FileName")%>">删除</A> </td>
</tr>
<%
rs.MoveNext
next
%>
<%
rs.Close
set rs=nothing
end if
%>
</table>
<br>
</body>
</html>
<%
function GetFilePath(FullPath,str)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, str))
Else
GetFilePath = ""
End If
End function
%>
我在上面的文件上传的form中又加了两个文本框我想看看能不能随图片一起添加进去~~
然后是savetodb.asp中:
<%OPTION EXPLICIT%>
<!--#include FILE="upfile_class.asp"-->
<%dim businame,busiclass
businame=trim(request.form("businame"))
busiclass=trim(request.form("busiclass"))
dim upfile,formPath,ServerPath,FSPath,formName,FileName,oFile,rs,conn
set upfile=new upfile_class ''建立上传对象
upfile.GetData (10240000) '取得上传数据,限制最大上传10M
%>
<html>
<head>
<title>文件上传</title>
<style type="text/css">
<!--
.p9{ font-size: 9pt; font-family: 宋体 }
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body leftmargin="20" topmargin="20" class="p9">
<p class="tx1"><font color="#0000FF" size="4"><%=upfile.Version%> </font></p>
<hr size=1 noshadow width=300 align=left><%
if upfile.err > 0 then '如果出错
select case upfile.err
case 1
Response.Write "你没有上传数据呀???是不是搞错了??"
case 2
Response.Write "你上传的文件超出我们的限制,最大10M"
end select
else
'如果你的服务器采用较老版本Access驱动,请用下面连接方法
'connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("dbbase.mdb")
conn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("dbase.mdb")
set rs=Server.CreateObject("adodb.recordset")
rs.Open "select * from FileInfo",conn,1,3
FSPath=GetFilePath(Server.mappath("upfile.asp"),"\")'取得当前文件在服务器路径
ServerPath=GetFilePath(Request.ServerVariables("HTTP_REFERER"),"/")'取得在网站上的位置
%>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" class="p9" style="border-collapse: collapse">
<tr bgcolor="#CCCCCC">
<td height="25" valign='middle'> 本地文件 </td>
<td valign='middle'> 大小(字节) </td>
<td valign='middle'> 上传到 </td>
</tr>
<%
for each formName in upfile.file '列出所有上传了的文件
set oFile=upfile.file(formname)
FileName=upfile.form(formName)'取得文本域的值
if not FileName>"" then FileName=oFile.filename'如果没有输入新的文件名,就用原来的文件名
rs.AddNew
rs("FileName")=FileName
rs("FilePath")=oFile.FilePath&oFile.FileName
rs("FileType")=oFile.FileType
rs("FileExt")=oFile.FileExt
rs("FileData")=oFile.FileData
rs("FileSize")=oFile.FileSize
rs("businame")=businame
rs("busiclass")=busiclass
rs.Update
%>
<tr>
<td height="20" valign='middle'> <%=oFile.FilePath&oFile.FileName%> </td>
<td valign='middle'> <%=oFile.filesize%></td>
<td valign='middle'> <A HREF="<%=serverpath&"readdbfile.asp?filename="&FileName%>"><%=FileName%></A> </td>
</tr><%
set oFile=nothing
next
%>
<tr>
<td colspan="3" height="25" valign='middle'> 一共上传了<%=upfile.file.Count%>个文件</td>
</tr>
<%
rs.Close
set rs=nothing
end if
set upfile=nothing '删除此对象
%>
</table>
<p></p>
</p>
[<a href="javascript:history.back();">返回</a>]
</body>
</html>
<%
function GetFilePath(FullPath,str)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, str))
Else
GetFilePath = ""
End If
End function
%>
可是这样不行,也就是说图片和文字能不能直接一起添加呢?