幸田来未15th:asp上传文件和文本框问题
我的代码如下:
addsoft.asp文件代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<p> </p>
<form action="/infosoft/checkadd.asp" method="post" name="addsoft" id="addsoft" enctype="multipart/form-data">
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellspacing="1">
<tr>
<td colspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="230" height="40" background="/Images/addsoft.jpg"> </td>
<td background="/Images/top_bg.gif"> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="30">教程名称:</td>
<td><input name="softname" type="text" id="softname"></td>
</tr>
<tr>
<td height="30">教程类型:</td>
<td><input name="ID_sort" type="text" id="ID_sort"></td>
</tr>
<tr>
<td height="30">发布用户:</td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td height="30">相关网页:</td>
<td><input name="web" type="text" id="web"></td>
</tr>
<tr>
<td height="30">是否推荐:</td>
<td><input type="radio" name="tuijian" value="1">
是
<input type="radio" name="tuijian" value="0">
否</td>
</tr>
<tr>
<td height="30">教程文件:</td>
<td><input type="file" name="fname"></td>
</tr>
<tr>
<td height="30"> </td>
<td><input type="submit" name="Submit" value="开始添加">
<input type="reset" name="Submit2" value="全部重写"></td>
</tr>
</table></td>
</tr>
</table>
</form>
<p> </p>
</body>
</html>
checkadd.asp内容如下..
<%@ LANGUAGE=VBScript CodePage=936%>
<%Response.Buffer=True%>
<!--#include FILE="UPLOAD.INC"-->
<!--#include file="conn.asp"-->
<html>
<head>
<LINK href="index.css" type=text/css rel=stylesheet>
<title>文件上传</title>
</head>
<body>
<%
dim upload,file,formName,formPath,iCount,filename,fileext
set upload=new upload_5xSoft ''建立上传对象
if upload.form("filepath")="" then ''得到上传目录
HtmEnd "请输入要上传至的目录!"
set upload=nothing
response.end
else
id=upload.form("id")
formPath=upload.form("filepath")
iid=upload.form("iid")
page=upload.form("page")
''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
end if
iCount=0
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
fileExt=lcase(right(file.filename,4))
if fileEXT<>".gif" and fileEXT<>".jpg" and fileEXT<>".bmp" then
response.write "<p align=center>文件格式不对 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
response.end
end if
if file.filesize>80000 then
response.write "<p align=center>文件大小超过了限制 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
response.end
end if
filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&right(file.FileName,4)
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath(filename) ''保存文件
end if
set file=nothing
next
set upload=nothing
'记录入库
Set rs=Server.CreateObject("ADODB.Recordset")
sql="select * from photo where i_id="&id
rs.open sql,conn,3,3
rs("pic")=filename
did=rs("did")
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
if page<>"" then
response.redirect "admin_06/photo.asp?id="&iid&"&page="&page&"&did="&did
else
response.redirect "admin_06/photo.asp?id="&iid&"&did="&did
end if
response.end
%>
</body>
</html>
上面的内容跟你的不一样,但是你把应该改的地方改改就成了. username=upload.form("username")关键是这里.
http://mytju.com/classCode/class_download.asp
看里面的:稻香老农的无组件上传类(化境无组件上传类)V2.0版
里面有详细的说明……
不推荐把文件写进数据库,这样久而久之,数据库会很庞大的,用个无组件上传类,
dim softname,id_sort依次...
softname = request.form("softname")
id_sort = reuqest.form("id_sort")
依次...
dim rsobj,sqlstr
set rsobj = server.createobject("adodb.recordset")
sqlstr = "select * from table"
rsobj.open sqlstr,conn,1,2
rsobj.addnew
rsobj("softname") = softname
rsobj("id_sort") = id_sort
依次....
rsobj.update
rsobj.close:set rsobj = nothing
conn.close:set conn = nothing
response.write "添加成功!"