1.ASP 上是N个单元格每个单元格里都有文本域和上传按钮。点击第2个按钮打开2.asp, 2.asp是一个上传小界面 里面是文件域和上传。点击浏览弹出选择图片,选择后在2.asp上的文本域上有文件路径。点击上传后把文件上传后的路径写到1.asp的第2个文本域,返回值是根据不同单元格里不同的上传按钮来实现的。我现在可以上传并返回了,但是我得做N个2.asp才能实现。怎样用1个2.asp就能做到呢?
1.asp 文本域和按钮1
<input name="txt1" type="text" class="iText" id="txt1" size="10" />
<input class="iButton" type="button" onclick="window.open('2.asp','_blank','Width=480 Height=50 top=300 left=300 status=1');" value="上传" />
下边是按钮2以此类推 文本域名称就是txt2、txt3等每个文本域后边都有按钮。
2.asp
<!--#include file="upload_class.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title> </title>
<style type="text/css">
TABLE {border:1px green solid;margin-top:5px;}
TD{border-bottom:1px #dddddd solid;height:20px;padding:3px 0 0 5px;}
.head{background-color:#eeeeee;}
</style>
</head>
<body style="font-size:12px">
请选择一个文件进行上传: <br />
<form name="upload" method="post" action="2.asp?act=upload" enctype="multipart/form-data">
选择文件:
<input class="iFile" id="file1" type="file" name="file1" size="30" />
<input class="iButton" type="submit" value="上传" />
</form> <%
if request.querystring("act")="upload" then
Dim Upload,successful,tempCls,image,smallImage
str="""" '===============================================================================
set Upload=new AnUpLoad '创建类实例
Upload.SingleSize=2048*2048 '设置单个文件最大上传限制,按字节计;默认为不限制
Upload.MaxSize=2048*2048 '设置最大上传限制,按字节计;默认为不限制
Upload.Exe="jpg|bmp|gif" '设置合法扩展名,以|分割,忽略大小写
Upload.GetData() '获取并保存数据,必须调用本方法
'===============================================================================
if Upload.Err>0 then '判断错误号,如果myupload.Err <=0表示正常
response.write Upload.Description '如果出现错误,获取错误描述
else
if Upload.forms("file1") <>"" then '这里判断你file1是否选择了文件
path=server.mappath("/files") '文件保存路径(这里是files文件夹)
set tempCls=Upload.files("file1")
successful=tempCls.SaveToFile(path,0)'以时间+随机数字为文件名保存
'successful=tempCls.SaveToFile(path,1)'如果想以原文件名保存,请使用本句
if successful then
str="files/" & tempCls.FileName
end if
set tempCls=nothing
end if end if
set Upload=nothing '销毁类实例
if str <>"" then
%>
<script type="text/javascript">
window.opener.document.all.txt1.value=' <%=str%>';
window.opener=null;
window.close();
</script> <%
end if end if
%>
</body>
</html> 'window.opener.document.all.txt.value=' <%=str%>' 这句里的TXT1就是1.asp上的文本域1。问题是如何这里如何动态的获得1.asp上不同的文本域按钮呢?
1.asp 文本域和按钮1
<input name="txt1" type="text" class="iText" id="txt1" size="10" />
<input class="iButton" type="button" onclick="window.open('2.asp','_blank','Width=480 Height=50 top=300 left=300 status=1');" value="上传" />
下边是按钮2以此类推 文本域名称就是txt2、txt3等每个文本域后边都有按钮。
2.asp
<!--#include file="upload_class.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title> </title>
<style type="text/css">
TABLE {border:1px green solid;margin-top:5px;}
TD{border-bottom:1px #dddddd solid;height:20px;padding:3px 0 0 5px;}
.head{background-color:#eeeeee;}
</style>
</head>
<body style="font-size:12px">
请选择一个文件进行上传: <br />
<form name="upload" method="post" action="2.asp?act=upload" enctype="multipart/form-data">
选择文件:
<input class="iFile" id="file1" type="file" name="file1" size="30" />
<input class="iButton" type="submit" value="上传" />
</form> <%
if request.querystring("act")="upload" then
Dim Upload,successful,tempCls,image,smallImage
str="""" '===============================================================================
set Upload=new AnUpLoad '创建类实例
Upload.SingleSize=2048*2048 '设置单个文件最大上传限制,按字节计;默认为不限制
Upload.MaxSize=2048*2048 '设置最大上传限制,按字节计;默认为不限制
Upload.Exe="jpg|bmp|gif" '设置合法扩展名,以|分割,忽略大小写
Upload.GetData() '获取并保存数据,必须调用本方法
'===============================================================================
if Upload.Err>0 then '判断错误号,如果myupload.Err <=0表示正常
response.write Upload.Description '如果出现错误,获取错误描述
else
if Upload.forms("file1") <>"" then '这里判断你file1是否选择了文件
path=server.mappath("/files") '文件保存路径(这里是files文件夹)
set tempCls=Upload.files("file1")
successful=tempCls.SaveToFile(path,0)'以时间+随机数字为文件名保存
'successful=tempCls.SaveToFile(path,1)'如果想以原文件名保存,请使用本句
if successful then
str="files/" & tempCls.FileName
end if
set tempCls=nothing
end if end if
set Upload=nothing '销毁类实例
if str <>"" then
%>
<script type="text/javascript">
window.opener.document.all.txt1.value=' <%=str%>';
window.opener=null;
window.close();
</script> <%
end if end if
%>
</body>
</html> 'window.opener.document.all.txt.value=' <%=str%>' 这句里的TXT1就是1.asp上的文本域1。问题是如何这里如何动态的获得1.asp上不同的文本域按钮呢?
Request 对象, ASP 0208 (0x80004005)
调用 BinaryRead 之后,不能使用一般 Request 集合。
意思已经告诉你了
试试request.querystring("name")