多个文件上传,一般处理程序
2021-05-17 22:28
YPE html>
标签:namespace primary sum jquery combine ext tle false ota
文件上传
等待
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
namespace 上传文件进度条.Hander
{
///
/// Handler1 的摘要说明
///
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
try
{
//从Request中取参数,注意上传的文件在Requst.Files中
string name = context.Request["name"];
string name1 = context.Request["name1"];
string name2 = context.Request["name2"];
int total = Convert.ToInt32(context.Request["total"]);
int index = Convert.ToInt32(context.Request["index"]);
var data = context.Request.Files["data"];
var data1 = context.Request.Files["data1"];
var data2 = context.Request.Files["data2"];
//保存一个分片到磁盘上
string dir = context.Request.MapPath("/Models/");
string file = Path.Combine(dir, name );
string file1 = Path.Combine(dir, name1 );
string file2 = Path.Combine(dir, name2 );
data.SaveAs(file);
data1.SaveAs(file1);
data2.SaveAs(file2);
//如果已经是最后一个分片,组合
//当然你也可以用其它方法比如接收每个分片时直接写到最终文件的相应位置上,但要控制好并发防止文件锁冲突
if (index == total)
{
file = Path.Combine(dir, name);
//byte[] bytes = null;
using (FileStream fs = new FileStream(file, FileMode.OpenOrCreate))
{
for (int i = 1; i {
string part = Path.Combine(dir, name + "_" + i);
//bytes = System.IO.File.ReadAllBytes(part);
//fs.Write(bytes, 0, bytes.Length);
//bytes = null;
System.IO.File.Delete(part);
fs.Close();
}
}
}
}
catch (Exception e)
{
throw;
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
多个文件上传,一般处理程序
标签:namespace primary sum jquery combine ext tle false ota
原文地址:http://www.cnblogs.com/cyh1995/p/7741815.html