首页 > 代码库 > Jquery Uploadify4.2 falsh 实现上传
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=http://www.mamicode.com/"javascript:$(‘#file_upload‘).uploadify(‘upload‘,‘*‘)"><i class="icon-save"></i>upload </a>| 9 <a href=http://www.mamicode.com/"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>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。