像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
}
}
}
地址:
相关文章推荐
- 像google,QQ,163那样一次上传多个文件
- 像google,QQ,163那样一次上传多个文件(downmoon)
- Crontab中shell每分钟执行一次HDFS文件上传不执行的解决方案
- WEB版一次选择多个文件进行批量上传(Plupload)的解决方案
- [Plugin] WEB版一次选择多个文件进行批量上传(swfupload)的解决方案
- WEB版一次选择多个文件进行批量上传(swfupload)的解决方案
- 一次小小的上传文件测试
- Springmvc下一次选多个文件上传(一)Form提交
- Spring文件上传,包括一次选中多个文件
- Linux命令行下,svn add 一次增加多个文件并批量上传
- 访163网盘文件上传效果
- cdn缓存导致的一次上传并转码覆盖源文件,导致文件有的不能访问问题
- file文件添加change事件,结合ajaxFileUpload使用文件上传只生效一次问题解决
- asp.net 2.0中允许一次上传多个文件的设计
- #SSH#关于SSH的扫盲—记一次利用SSH认证上传大文件
- 一次同时上传多个文件
- asp.net 中一次上传多个文件
- 仿163的多文件上传带增加删除功能
- C# 用file 上传文件大小时判断文件大小 file onchange 事件为什么只执行一次解决方案
- 解决<input type=“file” multiple> 多文件上传问题(可以多次选取文件,也可以一次选取多个文件),而且点击的是一个同一个div