码迷,mamicode.com
首页 > 其他好文 > 详细

plupload文件合并

时间:2018-01-03 11:44:48      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:files   saveas   span   exist   json   rpc   parse   main   created   

MVC

/// <summary>
/// 文件上传
/// </summary>
/// <returns></returns> 
public JsonResult plupload(string name)
{ 
    string msg = string.Empty;
    string strchunk = Request["chunk"];
    string strchunks = Request["chunks"];
    int chunk = 0;
    int chunks = 0;
    int.TryParse(strchunk, out chunk);
    int.TryParse(strchunks, out chunks);

    foreach (string upload in Request.Files)
    {
        if (upload != null && upload.Trim() != "")
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            System.Web.HttpPostedFileBase postedFile = Request.Files[upload];
            string filename1 = Path.GetFileName(postedFile.FileName);
            string filename = name;
           
            string newFileName = filename;
            if (chunks>1)
            {
                newFileName = chunk + "_" + filename;
            }
            string fileNamePath = path + newFileName;
            postedFile.SaveAs(fileNamePath);

            if (chunks>1 && chunk + 1 == chunks)
            {
                using (FileStream fsw = new FileStream(path + filename, FileMode.Create, FileAccess.Write))
                {
                    BinaryWriter bw = new BinaryWriter(fsw);
                    // 遍历文件合并 
                    for (int i = 0; i < chunks; i++)
                    {
                        bw.Write(System.IO.File.ReadAllBytes(path + i.ToString() + "_" + filename));
                        bw.Flush();
                    }
                }

            }
             
        }
    } 
    return Json(new { jsonrpc = "2.0", result = "", id = "id" });
   
}

 

plupload文件合并

标签:files   saveas   span   exist   json   rpc   parse   main   created   

原文地址:https://www.cnblogs.com/zhuxiang1633/p/8182118.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!