首页 > 代码库 > Uploadpropic Controller
Uploadpropic Controller
#region 上传到服务器图片 [HttpPost] public JsonResult Uploadpropic() { string msg = string.Empty; string filePath = string.Empty; string success = "0"; var fileList = Request.Files; if (fileList.Count > 0) { HttpPostedFileBase file = Request.Files[0]; int lenth = file.ContentLength; if (lenth < 3000000) { string extFile = System.IO.Path.GetExtension(file.FileName); if (!string.IsNullOrWhiteSpace(extFile)) { extFile = extFile.ToLower(); if (extFile == ".jpg" || extFile == ".png" || extFile == ".jpeg") { filePath = "../upload/" + setRandomstr() + extFile; string filesyspath = System.IO.Path.Combine(Server.MapPath(filePath)); using (Stream fileStream = file.InputStream) { using (Bitmap bitmap = ImageHelper.GetThumImage(fileStream)) { if (bitmap != null) { bitmap.Save(filesyspath, ImageFormat.Jpeg); msg = "图片上传成功"; success = "1"; } else { msg = "图片上传失败,请重试"; } } } } else { msg = "只允许上传jpg|jpeg|png格式的图片"; } } else { msg = "上传的图片格式不正确"; } } else { msg = "请将图片大小修改为3M以内"; } } else { msg = "请选择要上传的图片"; } return Json(new { result = success, path = filePath, msg = msg }, JsonRequestBehavior.AllowGet); } #endregion
Uploadpropic Controller
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。