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)); }
public JsonResult FileUpload() { ViewModels.BaseJsonData json = new ViewModels.BaseJsonData(); var file = Request.Files["data"]; if (file == null) { json.state = 0; json.msg_text = "没有文件,请重新上传。"; } if (!extension.Contains(io.Path.GetExtension(file.FileName).ToLower())) { json.state = 0; json.msg_text = "上传文件不在允许的格式范围内。"; } string dtStr = DateTime.Now.ToString("yyyyMMdd"); string TempDir = string.Format("{0}{1}\\", attachmentTempPath, dtStr); if (!io.Directory.Exists(TempDir)) { io.Directory.CreateDirectory(TempDir); } string file_name = string.Format("{0}{1}", TempDir, file.FileName); string temp_file = SetSameName(file_name); file.SaveAs(temp_file); string fileName = io.Path.GetFileName(temp_file); json.state = 1; json.data = string.Format("{0}/{1},{2}\\{3},{4}", dtStr, fileName, dtStr, fileName, fileName); return(Json(json)); }