您的位置:首页 > 编程语言 > Go语言

像google,QQ,163那样一次上传多个文件

2011-07-11 18:11 387 查看

前台页面
<formid="frmUpload"runat="server"enctype="multipart/form-data">
<div>
<tablewidth="100%"border="0px"cellpadding="0px"cellspacing="2">
<trheight="80">
<tdalign="right"bgcolor="#EAEAEA">
上传图片:</td>
<tdbgcolor="#f7f7f7"valign="top">
<tablecellspacing="0"cellpadding="0"width="100%"align="left"border="0">
<trheight="30">
<tdclass="tab_font_left"align="left"width="100%">
<div>
<tablewidth="100%"border="0"cellpadding="2"cellspacing="1"id="SignFrame">
<trid="trHeader"align="center">
<tdwidth="60"height="25px;"align="center"bgcolor="#1C5E55"style="color:#FFFFFF">
序号</td>
<tdbgcolor="#1C5E55"align="center"style="color:#FFFFFF">
上传文件</td>
</tr>
</table>
</div>
<div>
<inputtype='file'style="display:none;"size='50'id="file1"runat="server"/>
<inputtype="button"name="Submit"value="添加上传文件"onclick="AddSignRow()"/>

<inputtype="button"name="Submit2"value="清空"onclick="ClearAllSign()"/>
<inputname='txtTRLastIndex'type='hidden'id='txtTRLastIndex'value="1"/>
<br/>
<spanclass="notetext">注:最多只能上传三个图片,如果需要更新,请先删除原图片</span>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div>
<tablewidth="100%"border="0"cellpadding="0"cellspacing="0"align="center">
<trheight="30">
<tdalign="center"colspan="2"bgcolor="#f7f7f7">
<asp:ButtonID="btnInsert"Text="确认添加"runat="server"OnClick="btnInsert_Click"/><asp:ButtonID="btnBack"Text="放弃返回"runat="server"/>
</td>
</tr>
</table>
</div>

</form>

脚本:

<scripttype="text/javascript"language="javascript">
<!--
varTempCount=1;//不可删除!downmoon20071025
//Example:obj=findObj("image1");
functionfindObj(theObj,theDoc)
{
varp,i,foundObj;
if(!theDoc)theDoc=document;
if((p=theObj.indexOf("?"))>0&&parent.frames.length)
{
theDoc=parent.frames[theObj.substring(p+1)].document;
theObj=theObj.substring(0,p);
}
if(!(foundObj=theDoc[theObj])&&theDoc.all)foundObj=theDoc.all[theObj];
for(i=0;!foundObj&&i<theDoc.forms.length;i++)
foundObj=theDoc.forms[i][theObj];
for(i=0;!foundObj&&theDoc.layers&&i<theDoc.layers.length;i++)
foundObj=findObj(theObj,theDoc.layers[i].document);
if(!foundObj&&document.getElementById)foundObj=document.getElementById(theObj);

returnfoundObj;
}
functionAddSignRow()
{
if(TempCount>3)return;
vartxtTRLastIndex=findObj("txtTRLastIndex",document);
varrowID=parseInt(txtTRLastIndex.value);
varsignFrame=findObj("SignFrame",document);
varnewTR=signFrame.insertRow(signFrame.rows.length);
newTR.id="SignItem"+rowID;
varnewNameTD=newTR.insertCell(0);
newNameTD.innerHTML=newTR.rowIndex.toString();
varnewNameTD=newTR.insertCell(1);
newNameTD.innerHTML="<inputname='MyFile"+rowID+"'id='MyFile"+rowID+"'type='file'size='50'/>";
txtTRLastIndex.value=(rowID+1).toString();
TempCount=TempCount+1;
}
functionDeleteSignRow(rowid)
{
varsignFrame=findObj("SignFrame",document);
varsignItem=findObj(rowid,document);
varrowIndex=signItem.rowIndex;
signFrame.deleteRow(rowIndex);
for(i=rowIndex;i<signFrame.rows.length;i++){
signFrame.rows[i].cells[0].innerHTML=i.toString();
}
}
functionClearAllSign()
{
if(confirm('确定要清空所有上传的文件吗?')){
varsignFrame=findObj("SignFrame",document);
varrowscount=signFrame.rows.length;
for(i=rowscount-1;i>0;i--){
signFrame.deleteRow(i);
}
vartxtTRLastIndex=findObj("txtTRLastIndex",document);
txtTRLastIndex.value="1";
TempCount=1;
AddSignRow();
}
}
//-->
</script>

后台代码:

protectedvoidbtnInsert_Click(objectsender,EventArgse)
{
HttpFileCollectionfiles=HttpContext.Current.Request.Files;
for(intiFile=1;iFile<=Request.Files.Count;iFile++)
{///'检查文件扩展名字
HttpPostedFilepostedFile=files[iFile-1];
if(postedFile!=null&&postedFile.ContentLength>0)
{
//UploadFile
}
}
}

地址:http://www.cnblogs.com/downmoon/archive/2008/07/23/1249410.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: