Jquery Uploadify4.2 falsh 实现上传
html:
1 <div id="fileQueue"> 2 <table style="table-layout: fixed; width: 35%"> 3 <tr> 4 <td>@Html.TextBoxFor(ModelItem => Model.SVNSourceCodeURL, new { @type = "hidden", @id = "UploadedFile" }) 5 <input type="file" id="file_upload" name="file_upload" /> 6 </td> 7 <td style="width:10%"><i id="mark"></i></td> 8 <td><a href="javascript:$(‘#file_upload‘).uploadify(‘upload‘,‘*‘)"><i class="icon-save"></i>upload </a>| 9 <a href="javascript:$(‘#file_upload‘).uploadify(‘cancel‘)"><i class="icon-trash"></i>cancel</a></td> 10 </tr> 11 </table> 12 </div>
Ajax:
1 $("#file_upload").uploadify({ 2 queueID: ‘fileQueue‘, 3 swf: ‘@Url.Content("~/js/uploadify.swf")‘, 4 uploader: ‘@Url.Action("UploadFile", "Controller")‘, 5 buttonText: ‘<i class="icon-search"></i> Browse‘, 6 fileSizeLimit: ‘500MB‘, 7 fileTypeDesc: ‘Zip Files‘, 8 fileTypeExts: ‘*.zip‘, 9 auto: false, 10 width: 100, 11 height: 30, 12 removeCompleted: false, 13 fileObjName: ‘fileData‘, 14 onUploadSuccess: function (file, data) { 15 var obj = eval("(" + data + ")"); 16 $("#UploadedFile").val(obj.fileName); 17 if (obj.result == "Success") { 18 $("#mark").addClass("icon-ok"); 19 } 20 }, 21 formData: { folder: ‘/UploadedZipFiles‘} 22 });
CS
1 [HttpPost] 2 public JsonResult UploadFile(string folder, HttpPostedFileBase fileData) 3 { 4 if (fileData != null && fileData.ContentLength > 0) 5 { 6 try 7 { 8 string ext = Path.GetExtension(fileData.FileName); 9 string name = Guid.NewGuid().ToString() + ext; 10 string fullname = Path.Combine(Server.MapPath(folder), name); 11 fileData.SaveAs(fullname); 12 return Json(new { result ="Success", fileName = name}, JsonRequestBehavior.AllowGet); 13 } 14 catch (Exception e) 15 { 16 return Json(new { result ="Fail!" + e.ToString(), fileName = null}, JsonRequestBehavior.AllowGet); 17 } 18 } 19 return Json(new { result ="No File", fileName = null}, JsonRequestBehavior.AllowGet); 20 }
webConfig
<system.web> <httpRuntime maxRequestLength="999999999" executionTimeout="50000" /> </system.web>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。