/// <summary> /// 注册 /// </summary> /// <returns></returns> public ActionResult Reg() { //打开获取一个token,作为redis存放验证码的key string Token = UniqueObjectID.GenerateStrNewId(); ViewBag.Token = Token; return(View()); }
public ResponseEntity <List <string> > Post() { ResponseEntity <List <string> > result = new ResponseEntity <List <string> >(); List <string> imgPathList = null; string filePath = ""; HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; if (files.Count > 0) { imgPathList = new List <string>(); int imgFunc = Convert.ToInt32(HttpContext.Current.Request.Form["func"]); string msg = ""; for (int i = 0; i < files.Count; i++) { try { HttpPostedFile f = files[i]; string FileName = f.FileName; string Pattern = FileName.Substring(FileName.LastIndexOf(".") + 1).ToLower(); if (!Const.ImgPattern.Contains(Pattern)) { imgPathList.Add("上传文件类型错误"); msg = "有文件上传失败!"; continue; } //根据word类型决定存放word的相对路径 string path = ""; path = "\\img\\" + imgFunc; string saveName = UniqueObjectID.GenerateStrNewId(); filePath = FileHelper.SaveFile(f, path, saveName); imgPathList.Add(filePath.Replace("\\", "/")); } catch (Exception ex) { imgPathList.Add(ex.Message); msg = "有文件上传失败!"; } } result.Code = (int)ResponseCode.Success; result.BussCode = (int)ResponseBussCode.Success; result.Data = imgPathList; result.Message = msg; } else { result.Code = (int)ResponseCode.DataNotExist; result.BussCode = (int)ResponseBussCode.Error; result.Data = null; result.Message = "找不到任何上传的文件"; } return(result); }
public ResponseEntity <dtoWordUploadPath> Post() { ResponseEntity <dtoWordUploadPath> result = new ResponseEntity <dtoWordUploadPath>(); dtoWordUploadPath dto = new dtoWordUploadPath(); string filePath = ""; HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; if (files.Count > 0) { try { HttpPostedFile file = files[0]; string FileName = file.FileName; string Pattern = FileName.Substring(FileName.LastIndexOf(".") + 1); if (Pattern != "doc" && Pattern != "docx") { result.Code = (int)ResponseCode.ParamsError; result.BussCode = (int)ResponseBussCode.Error; result.Data = null; result.Message = "上传文件类型必须是doc/docx"; return(result); } //根据word类型决定存放word的相对路径 string path = ""; int wordFunc = Convert.ToInt32(HttpContext.Current.Request.Form["func"]); int wordCategory = Convert.ToInt32(HttpContext.Current.Request.Form["category"]); path = "\\word\\" + wordFunc + "\\" + wordCategory; string saveName = UniqueObjectID.GenerateStrNewId(); filePath = FileHelper.SaveFile(file, path, saveName); if (wordFunc == (int)Const.WordFunc.CreateZY) { //Word转Html string htmlPath = filePath.Replace("word", "html").Replace("docx", "html").Replace("doc", "html"); bool b = FileHelper.Word2Html(filePath, htmlPath); if (b) { dto.WordPath = filePath.Replace("\\", "/"); dto.HtmlPath = htmlPath.Replace("\\", "/"); result.Code = (int)ResponseCode.Success; result.BussCode = (int)ResponseBussCode.Success; result.Data = dto; result.Message = ""; } else { dto.WordPath = filePath.Replace("\\", "/"); dto.HtmlPath = ""; result.Code = (int)ResponseCode.Error; result.BussCode = (int)ResponseBussCode.Error; result.Data = dto; result.Message = "word转html失败!"; } } else { dto.WordPath = filePath.Replace("\\", "/"); dto.HtmlPath = ""; result.Code = (int)ResponseCode.Success; result.BussCode = (int)ResponseBussCode.Success; result.Data = dto; result.Message = ""; } } catch (Exception ex) { result.Code = (int)ResponseCode.Error; result.BussCode = (int)ResponseBussCode.Error; result.Data = null; result.Message = ex.Message; LogHelper.Error("上传Word报错,原因是:" + ex.Message); } } else { result.Code = (int)ResponseCode.DataNotExist; result.BussCode = (int)ResponseBussCode.Error; result.Data = null; result.Message = "找不到任何上传的文件"; } return(result); }