多文件上传
来源:互联网 发布:android视频类app源码 编辑:程序博客网 时间:2024/05/21 05:40
前台代码:
上传文件:
<div id="TdFile">
<div><INPUT id="OldFile" type="file" runat="server"><br></div>
</div>
添加一个文件
<input type="button" value="增加" onclick="AddFile();">
<input type="button" value="删除" class="button" onclick="DelFile();">
<asp:Button id="BtnUp" runat="server" Text="上传"></asp:Button>
<div id="TdFile">
<div><INPUT id="OldFile" type="file" runat="server"><br></div>
</div>
添加一个文件
<input type="button" value="增加" onclick="AddFile();">
<input type="button" value="删除" class="button" onclick="DelFile();">
<asp:Button id="BtnUp" runat="server" Text="上传"></asp:Button>
JavaScript代码:
function AddFile()
{
var td = document.getElementById("TdFile");
var obj = td.childNodes[0].cloneNode(true);
td.appendChild(obj);
}
function DelFile()
{
var td = document.getElementById("TdFile");
var l = td.childNodes.length;
if(l == 1)
{
window.alert("这是最后一个上传对象,不能删除");
}
else
{
td.removeChild(td.childNodes[l - 1]);
}
}
{
var td = document.getElementById("TdFile");
var obj = td.childNodes[0].cloneNode(true);
td.appendChild(obj);
}
function DelFile()
{
var td = document.getElementById("TdFile");
var l = td.childNodes.length;
if(l == 1)
{
window.alert("这是最后一个上传对象,不能删除");
}
else
{
td.removeChild(td.childNodes[l - 1]);
}
}
后台代码:
private void BtnUp_Click(object sender, System.EventArgs e)
{
System.Web.HttpFileCollection fils = Request.Files;
int i = 0;
int l = fils.Count;
while(i < l)
{
this.SaveFile(fils[i++]);
}
this.Message.Text = "文件上传成功!";
}
void SaveFile(System.Web.HttpPostedFile ipf)
{
if(ipf.FileName.Length > 1)
{
string fn = ipf.FileName.Substring(ipf.FileName.LastIndexOf("//") + 1);
string sfn = Server.MapPath(“images/upload/“) + fn;
if(File.Exists(sfn))//如果存在同名文件则删除
{
File.Delete(sfn);
}
ipf.SaveAs(sfn);
}
{
System.Web.HttpFileCollection fils = Request.Files;
int i = 0;
int l = fils.Count;
while(i < l)
{
this.SaveFile(fils[i++]);
}
this.Message.Text = "文件上传成功!";
}
void SaveFile(System.Web.HttpPostedFile ipf)
{
if(ipf.FileName.Length > 1)
{
string fn = ipf.FileName.Substring(ipf.FileName.LastIndexOf("//") + 1);
string sfn = Server.MapPath(“images/upload/“) + fn;
if(File.Exists(sfn))//如果存在同名文件则删除
{
File.Delete(sfn);
}
ipf.SaveAs(sfn);
}
- 文件上传(多文件)
- asp.net文件上传,多文件上传。
- 单文件上传、多文件上传
- struts2文件上传与多文件上传
- 单文件上传和多文件上传
- PHP文件上传功能 -- 多文件上传
- struts2文件上传(多文件上传)
- SpringMVC文件上传 多文件上传实例
- Struts2之文件上传,多文件上传
- SpringMVC文件上传 多文件上传实例
- 文件上传及多文件上传
- Spring boot 文件上传(多文件上传)
- Struts文件上传--2.多文件上传
- spring boot文件上传【多文件上传】
- FastDFS上传文件二 : 多文件上传
- 多文件上传
- 单/多文件上传
- 多个文件上传
- 验证码
- 技术人员行走职场三大陷阱之“熟人借钱”
- 技术人员行走职场三大陷阱之“胡乱跳槽”
- 技术人员行走职场三大陷阱之“盲目创业”
- switch case 的 一种用法
- 多文件上传
- 勾选checkbox后行变色代码
- DATAGRID中实现多行删除
- 李嘉诚谈管理艺术:想当老板还是领袖
- VPN技术原理
- 在spring中映射X.hbm.xml文件的小技巧
- ASP.NET中的状态管理
- 在 Ubuntu 中安装 JDK 6
- 非常有用的101道算法部分常见面试题