Jquery Uploadify4.2 falsh 實現上傳

來源:互聯網
上載者:User

標籤:des   style   c   class   blog   code   

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&nbsp;</a>|  9                                             <a href="javascript:$(‘#file_upload‘).uploadify(‘cancel‘)"><i class="icon-trash"></i>cancel</a></td>10                                     </tr>11                                 </table>12                             </div>
View Code

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>&nbsp;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         });
View Code

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         }            
View Code

webConfig

    <system.web><httpRuntime maxRequestLength="999999999" executionTimeout="50000" /></system.web>
View Code

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.