public JsonResult UploadPicture() { ViewModel.BaseJsonData json = new ViewModel.BaseJsonData(); var file = Request.Files["data"]; if (file == null) { json.state = 0; json.msg_text = "没有文件,请重新上传。"; } if (Path.GetExtension(file.FileName).ToLower() != ".jpg") { json.state = 0; json.msg_text = "请上传jpg格式文件。"; } string file_name = string.Format("{0}.jpg", DateTime.Now.ToString("yyyyMMddHHmmssfff")); string file_name_temp = string.Format("{0}_temp.jpg", DateTime.Now.ToString("yyyyMMddHHmmssfff")); string save_path = Server.MapPath(string.Format("~/images/temp/{0}", file_name)); string save_path_temp = Server.MapPath(string.Format("~/images/temp/{0}", file_name_temp)); file.SaveAs(save_path); ImageFun.MakeThumbnail(save_path, save_path_temp, 160, 0, "W"); json.state = 1; json.data = file_name_temp; return(Json(json)); }
public JsonResult UploadPicture() { ViewModels.BaseJsonData json = new ViewModels.BaseJsonData(); var file = Request.Files["data"]; if (file == null) { json.state = 0; json.msg_text = "没有文件,请重新上传。"; } if (Path.GetExtension(file.FileName).ToLower() != ".jpg") { json.state = 0; json.msg_text = "请上传jpg格式文件。"; } string photoTempDir = ConfigurationManager.AppSettings["tempPhotoPath"]; if (!Directory.Exists(photoTempDir)) { Directory.CreateDirectory(photoTempDir); } string guid = Guid.NewGuid().ToString("N"); string file_name = string.Format("{0}{1}.jpg", photoTempDir, guid); string file_name_temp = string.Format("{0}{1}_temp.jpg", photoTempDir, guid); file.SaveAs(file_name); ImageFun.MakeThumbnail(file_name, file_name_temp, 200, 0, "W"); json.state = 1; json.data = Path.GetFileName(file_name_temp); return(Json(json)); }