diff --git a/OpenAuth.Mvc/Areas/FlowManage/Controllers/FileController.cs b/OpenAuth.Mvc/Areas/FlowManage/Controllers/FileController.cs new file mode 100644 index 00000000..d8f8a8b7 --- /dev/null +++ b/OpenAuth.Mvc/Areas/FlowManage/Controllers/FileController.cs @@ -0,0 +1,75 @@ +using System; +using System.Configuration; +using System.IO; +using System.Web; +using System.Web.Mvc; +using Infrastructure; +using OpenAuth.Mvc.Controllers; + +namespace OpenAuth.Mvc.Areas.FlowManage.Controllers +{ + public class FileController : BaseController + { + + [HttpPost] + public string Upload(HttpPostedFileBase Filedata) + { + if (Filedata != null && Filedata.ContentLength > 0 && Filedata.ContentLength < 10485760) + { + using (var binaryReader = new BinaryReader(Filedata.InputStream)) + { + var fileName = Path.GetFileName(Filedata.FileName); + var data = binaryReader.ReadBytes(Filedata.ContentLength); + var result = UploadFile(fileName, data, string.Empty); + Result.Result = result; + } + } + else + { + Result.Message = "文件过大"; + Result.Status = false; + } + + return JsonHelper.Instance.Serialize(Result); + + } + + public string UploadFile(string fileName, byte[] fileBuffers, string folder) + { + if (string.IsNullOrEmpty(folder)) + { + folder = DateTime.Now.ToString("yyyy_MM_dd"); + } + + //判断文件是否为空 + if (string.IsNullOrEmpty(fileName)) + { + throw new Exception("文件名不能为空"); + } + + //判断文件是否为空 + if (fileBuffers.Length < 1) + { + throw new Exception("文件不能为空"); + } + + + var filePath =Server.MapPath("upload"); + var uploadPath = filePath +"\\" + folder + "\\"; + var ext = Path.GetExtension(fileName); + var newName = Guid.NewGuid().ToString("N") + ext; + + if (!Directory.Exists(uploadPath)) + { + Directory.CreateDirectory(uploadPath); + } + using (var fs = new FileStream(uploadPath + newName, FileMode.Create)) + { + fs.Write(fileBuffers, 0, fileBuffers.Length); + fs.Close(); + return folder + "/" + newName; + } + + } + } +} \ No newline at end of file diff --git a/OpenAuth.Mvc/Content/scripts/utils/applayout.js b/OpenAuth.Mvc/Content/scripts/utils/applayout.js index 3bd7babd..9f1d030c 100644 --- a/OpenAuth.Mvc/Content/scripts/utils/applayout.js +++ b/OpenAuth.Mvc/Content/scripts/utils/applayout.js @@ -1371,8 +1371,8 @@ $.fn.frmPreview = function (options) function fuploadify(control_field,btnName) { $("#" + control_field).uploadify({ method: 'post', - uploader: '/FlowManage/FormDesign/UploadifyFile', - swf: top.contentPath + '/Content/scripts/plugins/uploadify/uploadify.swf', + uploader: '/FlowManage/File/Upload', + swf: '/Content/scripts/plugins/uploadify/uploadify.swf', buttonText: btnName, height: 30, width: 90, diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj index afa2998f..31fb8dd3 100644 --- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj +++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj @@ -142,6 +142,7 @@ +