namespace YLErp.Web.Controllers { public class UeditorController : BaseController { public ActionResult Index() { var action = Request.Query["action"]; switch (action) { case "config": { var filePath = Server.MapPath("~/Scripts/ueditor/config.json"); var content = System.IO.File.ReadAllText(filePath); return Content(content, "application/json"); } case "uploadimage": return uploadimage(); } return Content(string.Empty, "application/json"); } private JsonResult uploadimage() { var result = new UploadResult { state = "SUCCESS" }; if (Request.Form.Files.Count < 1) { result.state = "文件不存在"; return Json(result); } var file = Request.Form.Files[0]; var ext = Path.GetExtension(file.FileName); if (".png|.jpg|.jpeg|.gif|.bmp".IndexOf(ext.ToLowerInvariant()) < 0) { result.state = "文件格式不支持"; return Json(result); } //10M文件大小限制 if (file.Length > 10 * 1024 * 1024) { result.state = "文件大小超过限制"; return Json(result); } var date = DateTime.Today; var fileName = Guid.NewGuid().ToString("N") + ext; var webpath = $"/app_upload/images/{date.Year}/{date.Month}/{fileName}"; var localPath = Server.MapPath(webpath); Directory.CreateDirectory(Path.GetDirectoryName(localPath)); file.SaveAs(localPath); result.url = webpath; result.title = file.FileName; result.original = file.FileName; result.size = file.Length; result.type = ext; return Json(result); } public ActionResult Config(string id) { ViewData["id"] = id; return View(); } class UploadResult { public string state { get; set; } public string url { get; set; } public string title { get; set; } public string original { get; set; } public string type { get; set; } public long size { get; set; } } } }