依然不多说,上代码
首先是给文件夹的位置
然后上代码
1 <div class="upload"> 2 <div class="uploadswf"> 3 <input type="file" name="uploadify" id="uploadify" style="vertical-align: middle;" /> 4 <span id="docspan"></span> 5 <p id="fileQueue" style="color:black; background-color:#3C8DBC;"></p> 6 </div> 7 </div>
1 <script type="text/javascript"> 2 $(function () { 3 $("#uploadify").uploadify({ 4 ‘uploader‘: ‘/plugins/uploadify-v2.1.4/uploadify.swf‘, 5 ‘script‘: ‘/Logistics/FileUpload?lcid=‘+id, 6 ‘cancelImg‘: ‘/plugins/uploadify-v2.1.4/cancel.png"‘, 7 ‘folder‘: ‘/Areas/Admin/UploadFile/ContractAtt/‘, 8 ‘queueID‘: ‘fileQueue‘, 9 ‘auto‘: true, 10 ‘multi‘: false, 11 ‘method‘: ‘post‘, 12 ‘fileExt‘: ‘*.jpg;*.png;*.doc;*.docx;*.xls;*.xlsx;*.zip;*.rar;‘, 13 ‘fileDesc‘: ‘请选择 jpg png doc docx xls xlsx zip rar 文件‘, 14 ‘scriptData‘: null, 15 ‘sizeLimit‘: 314572800, 16 ‘buttonText‘: ‘上传文件‘, 17 ‘onComplete‘: function (event, queueID, fileObj, respose, data) { 18 var data = $.parseJSON(respose); 19 if (data.err) { 20 $.tooltip("上传成功!", 2500, true); 21 return false; 22 } 23 } 24 }) 25 }) 26 <script>
控制器代码
1 [HttpPost] 2 public JsonResult FileUpload(HttpPostedFileBase fileData) 3 { 4 if (fileData != null) 5 { 6 int lcId = Convert.ToInt32(Request["lcid"]); 7 try 8 { 9 string filePath = Server.MapPath("/Areas/Admin/UploadFile/ContractAtt"); 10 string fileName = Path.GetFileName(fileData.FileName);//原始文件名 11 string fileExtension = Path.GetExtension(fileName);//扩展名 12 string saveName = lcId +"_"+ DateTime.Now.ToString("yyyyMMddhhmmss");//保存服务器文件名 13 string att = "/Areas/Admin/UploadFile/ContractAtt/" + saveName; 14 if (lcService.UpdataAtt(lcId, att)) 15 { 16 fileData.SaveAs(filePath +"\\"+ saveName+fileExtension); 17 return Json(new { err = true, FileName = fileName, SavaName = saveName }); 18 } 19 else 20 { 21 return Json(new { err = false, Message = "系统错误!" }, JsonRequestBehavior.AllowGet); 22 } 23 } 24 catch (Exception ex) 25 { 26 return Json(new { ess = false, Message = ex.Message }, JsonRequestBehavior.AllowGet); 27 } 28 } 29 else 30 { 31 return Json(new { err = false, Message = "请选择要上传的文件!" }, JsonRequestBehavior.AllowGet); 32 } 33 }
由于官方文件里面有两个文件有冲突,导致按钮上不能显示中文,故贴上修改好的文件,已修改完成可正常显示中文
http://pan.baidu.com/s/1o65TLFW
下面这是用未修改的效果图
时间: 2024-10-16 18:50:24