对于Uploadify文件上传之前已经讲过一次(),只不过没有涉及到多文件的上传,这回主要说一下多个文件的上传,首先,我们要清楚一个概念,多文件上传前端Uploadify是通过轮训的方式去调用我们的后台upload程序的,所以,对于多文件上传来说,也没什么稀奇的.
下面是文件上传后的缩略图如下
列表的组装使用JS模板,这样对于复杂的HTML结构来说,可以减少拼写错误的出现,关闭是将LI元素从UI元素移除,最后提交时,从UI里检查LI元素,然后对它进行组装,并进行发送下面是相关代码
一 HTML模版
二 uploadfiy代码
三 html代码
四 ashx代码
////// Summary description for UploadHandler /// public class UploadHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; HttpPostedFile file = context.Request.Files["Filedata"]; string uploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"]); if (file != null) { if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } file.SaveAs(Path.Combine(uploadPath, file.FileName)); var pathArr = uploadPath.Split('\\'); context.Response.Write(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + "/" + pathArr[pathArr.Length - 2] + "/" + pathArr[pathArr.Length - 1] + "/" + file.FileName); } else { context.Response.Write("0"); } } public bool IsReusable { get { return false; } } }
本实例只是简单的说明了文件上传的功能,如果在真实项目中使用的话,还需要进一步的进行代码的设计.