input file实现批量上传
生活随笔
收集整理的這篇文章主要介紹了
input file实现批量上传
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、需求實現word批量上傳。
2、使用插件jquery-form.js
3、html代碼
注意?multiple="multiple"
?
1 <form id="frm_upload" method="post" enctype="multipart/form-data"> 2 <input type="file" id="filepath" multiple="multiple" name="file" style="width: 60px; cursor: pointer" accept="application/msword" /> 3 </form>4、js代碼
1 $("#frm_upload").ajaxSubmit({ 2 url: "Public/UploadAttachZD", 3 type: "post", 4 success: function (ort) { 5 } 6 });5、后臺代碼
1 string uploadroot = Server.MapPath("~/upload") + "\\11"; 2 if (!Directory.Exists(uploadroot)) 3 Directory.CreateDirectory(uploadroot); 4 var files = Request.Files; 5 if (files.Count != 0) 6 { 7 for (int i = 0; i < files.Count; i++) 8 { 9 var pf = files[i]; 10 int npos = pf.FileName.LastIndexOf('.'); 11 string fileext = ""; 12 if (npos != -1) 13 { 14 fileext = pf.FileName.Substring(npos + 1); 15 } 16 string newfilepath = DateTime.Now.Ticks.ToString().ToLower() + "." + fileext; 17 pf.SaveAs(uploadroot + "\\" + newfilepath); 18 } 19 }?
轉載于:https://www.cnblogs.com/Lv2014/p/6006412.html
總結
以上是生活随笔為你收集整理的input file实现批量上传的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Decorator模式
- 下一篇: hadoop中HDFS命令遇到的问题