首页 > 代码库 > 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&nbsp;</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>
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