请大师级人物进来,帮忙看看,非常感谢大家~``````
任务:在一个表单中上传两张图片!分别保存在img文件夹中的两个小文件夹A和B中,并将图片地址显示在表单中,然后提交到数据库中,保存起来。
第一步:制作表单(index.asp)
<body>
<form name="myform" method="post" action="">
<p>
<input name="pic1" type="text" id="pic" size="30" VALUE="">
<input type="button" name="Submit11" value="上传图片" onClick="window.open('upfile.asp?formname=myform&editname=pic1&uppath=img/A&filelx=jpg','','status=no,scrollbars=no,top=20,left=110,width=420,height=165')">
</p>
<p><input name="pic2" type="text" id="pic" size="30" VALUE="">
<input type="button" name="Submit11" value="上传图片" onClick="window.open('upfile.asp?formname=myform&editname=pic2&uppath=img/B&filelx=jpg','','status=no,scrollbars=no,top=20,left=110,width=420,height=165')">
</p>
</form>
</body>
第二步:制作上传的界面表单(upfile.asp)
<%
uppath=request.QueryString("uppath")&"/"
filelx=request.QueryString("filelx")
formName=request.QueryString("formName")
EditName=request.QueryString("EditName")
%>
<html>
<head>
<title>图片上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">
<!--
function mysub()
{
esave.style.visibility="visible";
}
-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="upload.asp" enctype="multipart/form-data" >
<div id="esave" style="position:absolute; top:18px; left:40px; z-index:10; visibility:hidden">
<TABLE WIDTH=340 BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR><td width=20%></td>
<TD bgcolor=#104A7B width="60%">
<TABLE WIDTH=100% height=120 BORDER=0 CELLSPACING=1 CELLPADDING=0>
<TR>
<td bgcolor=#eeeeee align=center><font color=red>正在上传文件,请稍候...</font></td>
</tr>
</table>
</td><td width=20%></td>
</tr></table></div>
<table width="400" border="0" cellspacing="1" cellpadding="0" align="center" bgcolor="#6699ff">
<tr>
<td height="22" align="left" valign="middle" width="400"> 图片上传
<input type="hidden" name="filepath" value="<%=uppath%>">
<input type="hidden" name="filelx" value="<%=filelx%>">
<input type="hidden" name="EditName" value="<%=EditName%>">
<input type="hidden" name="FormName" value="<%=formName%>">
<input type="hidden" name="act" value="uploadfile">
</td>
</tr>
<tr align="center" valign="middle" bgcolor="#FFFFFF">
<td align="left" id="upid" height="80" width="400"> 选择文件:
<input type="file" name="file1" style="width:300'" class="tx1" value="">
</td>
</tr>
<tr align="center" valign="middle">
<td height="24" width="400">
<input type="submit" name="Submit" value="上传 " class="button" onclick="javascript:mysub()">
</td>
</tr>
</table>
</form>
</body>
</html>
第三步:上传文件(upload.asp)
<!--#include file="upload.inc"-->
<style>
td{font-size:9pt;line-height:120%;color:#353535}
body{font-size:9pt;line-height:120%}
a:link { color: #000000; text-decoration: none }
a:visited { color: #000000; text-decoration: none }
a:active { color: #000000; text-decoration: none }
a:hover { color: #336699; text-decoration: none; position: relative; right: 0px; top: 1px }
</style>
<%
set upload=new upload_file
if upload.form("act")="uploadfile" then
filepath=trim(upload.form("filepath"))
filelx=trim(upload.form("filelx"))
i=0
for each formName in upload.File
set file=upload.File(formName)
fileExt=lcase(file.FileExt) '得到的文件扩展名不含有.
if file.filesize<100 then
response.write "<span style=""font-family: 宋体; font-size: 9pt"">请先选择你要上传的文件! [ <a href=# onclick=history.go(-1)>重新上传</a> ]</span>"
response.end
end if
if (filelx<>"swf") and (filelx<>"jpg") then
response.write "<span style=""font-family: 宋体; font-size: 9pt"">该文件类型不能上传! [ <a href=# onclick=history.go(-1)>重新上传</a> ]</span>"
response.end
end if
if filelx="swf" then
if fileext<>"swf" then
response.write "<span style=""font-family: 宋体; font-size: 9pt"">只能上传swf格式的Flash文件! [ <a href=# onclick=history.go(-1)>重新上传</a> ]</span>"
response.end
end if
end if
if filelx="jpg" then
if fileext<>"gif" and fileext<>"jpg" then
response.write "<span style=""font-family: 宋体; font-size: 9pt"">只能上传jpg或gif格式的图片! [ <a href=# onclick=history.go(-1)>重新上传</a> ]</span>"
response.end
end if
end if
if filelx="swf" then
if file.filesize>(3000*1024) then
response.write "<span style=""font-family: 宋体; font-size: 9pt"">最大只能上传 3M 的Flash文件! [ <a href=# onclick=history.go(-1)>重新上传</a> ]</span>"
response.end
end if
end if
if filelx="jpg" then
if file.filesize>(1000*1024) then
response.write "<span style=""font-family: 宋体; font-size: 9pt"">最大只能上传 1000K 的图片文件! [ <a href=# onclick=history.go(-1)>重新上传</a> ]</span>"
response.end
end if
end if
randomize
ranNum=int(90000*rnd)+10000
filename=filepath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
%>
<%
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
'file.SaveAs Server.mappath(filename) ''保存文件
file.SaveToFile Server.mappath(FileName)
'response.write file.FileName&" 上传成功! <br>"
'response.write "新文件名:"&FileName&"<br>"
'response.write "新文件名已复制到所需的位置,可关闭窗口!"
if filelx="swf" then
response.write "<script>window.opener.document."&upload.form("FormName")&".size.value='"&int(file.FileSize/1024)&" K'</script>"
end if
response.write "<script>window.opener.document."&upload.form("FormName")&"."&upload.form("EditName")&".value='"&FileName&"'</script>"
%>
<%
end if
set file=nothing
next
set upload=nothing
end if
%>
<script language="javascript">
window.alert("文件上传成功!");
window.close();
</script>