public ActionResult UploadFileDownload() { HttpPostedFileBase myFile = Request.Files["DownloadUpload"]; bool isUploaded = false; string message = "上传失败!"; //缩略图图片路径 string fileType = ""; string ImgRootUrl = string.Empty; string sizestr = ""; if (myFile != null && myFile.ContentLength != 0) { string pathForSaving = string.Empty; fileType = FileHelper.GetDownLoadTag(myFile.FileName); double size = Math.Round(myFile.ContentLength * 1.0 / 1024 * 1.0, 2); if (size > 1024) { size = Math.Round(size * 1.0 / 1024 * 1.0, 2); sizestr = size + "MB"; } else { sizestr = size + "KB"; } pathForSaving = ImagePathInfo.ProcessBeginOfThePath("/DownLoad/Files"); if (this.CreateFolderIfNeeded(pathForSaving)) { try { //图片路径处理 var ImgUrl = new ImagePathInfo(myFile.FileName, pathForSaving); //如果路径不存在则新建 ImgUrl.CreateDirectory(); //保存图片 myFile.SaveAs(ImgUrl.FileAbsolutePath); isUploaded = true; //保存后的图片路径 message = ImgUrl.FileRelativePath; } catch (Exception ex) { message = string.Format("File upload failed: {0}", ex.Message); } } } return(Json(new { isUploaded = isUploaded, message = message, form = fileType, size = sizestr }, "text/html")); }
public ActionResult DecIndexImgUpload() { HttpPostedFileBase myFile = Request.Files["DecImageUpload"]; //获取图片的种类对应图片文件夹名称(公司,工人,设计师,或案例) string ImageType = "PeopleCenter"; bool isUploaded = false; string message = "上传失败!"; string ImgRootUrl = string.Empty; if (myFile != null && myFile.ContentLength != 0) { string pathForSaving = string.Empty; string fileType = FileHelper.GetFileTag(myFile.FileName); if (fileType == "Image") { pathForSaving = ImagePathInfo.ProcessBeginOfThePath("/UploadFiles/Images/" + ImageType); //pathForSaving = Server.MapPath("~/UploadFiles/Images/"+ ImageType); } else { pathForSaving = ImagePathInfo.ProcessBeginOfThePath ("/UploadFiles/Files"); } if (this.CreateFolderIfNeeded(pathForSaving)) { try { //图片路径处理 var ImgUrl = new ImagePathInfo(myFile.FileName, pathForSaving); //如果路径不存在则新建 ImgUrl.CreateDirectory(); //保存图片 myFile.SaveAs(ImgUrl.FileAbsolutePath); isUploaded = true; //保存后的图片路径 message = ImgUrl.FileRelativePath; } catch (Exception ex) { message = string.Format("File upload failed: {0}", ex.Message); } } } return(Json(new { isUploaded = isUploaded, message = message }, "text/html")); }
public static string GetthumImgByUrl(string url) { string ret = ""; string filename = url.Substring(url.LastIndexOf('/') + 1, url.Length - url.LastIndexOf('/') - 1); string pathForSaving = ImagePathInfo.ProcessBeginOfThePath ("/UploadFiles/Files"); Image img = Url2Img(url); byte[] bit = ImageToByteArray(img); Stream stream = BytesToStream(bit); //缩略图处理 var thumbnailPathInfo = new ImagePathInfo(filename, pathForSaving); double hei = 290 * (Math.Round((img.Height * 1.0 / img.Width) * 1.0, 2)); int height = Convert.ToInt32(Math.Round(hei, 0)); using (var thumbNail = GetThumbnail(stream, 290, height, 100)) { thumbnailPathInfo.CreateDirectory(); thumbNail.Save(thumbnailPathInfo.FileAbsolutePath); } ret = thumbnailPathInfo.FileRelativePath; return(ret); }
public ActionResult ComCenterPictrueUpload() { HttpPostedFileBase myFile = Request.Files["ImageUpload"]; //获取图片的种类对应图片文件夹名称(公司,工人,设计师,或案例) string ImageType = "CompanyCenter"; //缩略图宽高 int thumwidth = Convert.ToInt32(Request["thumwidth"]) == 0 ? 100 : Convert.ToInt32(Request["thumwidth"]); int thumheight = Convert.ToInt32(Request["thumheight"]) == 0 ? 100 : Convert.ToInt32(Request["thumheight"]); int thumquality = Convert.ToInt32(Request["thumquality"]) == 0 ? 10 : Convert.ToInt32(Request["thumquality"]); bool isUploaded = false; string message = "上传失败!"; //缩略图图片路径 string thumbnailmessage = ""; string ImgRootUrl = string.Empty; if (myFile != null && myFile.ContentLength != 0) { string pathForSaving = string.Empty; string fileType = FileHelper.GetFileTag(myFile.FileName); if (fileType == "Image") { pathForSaving = ImagePathInfo.ProcessBeginOfThePath("/UploadFiles/Images/" + ImageType); //pathForSaving = Server.MapPath("~/UploadFiles/Images/"+ ImageType); } else { pathForSaving = ImagePathInfo.ProcessBeginOfThePath ("/UploadFiles/Files"); } if (this.CreateFolderIfNeeded(pathForSaving)) { try { //图片路径处理 var ImgUrl = new ImagePathInfo(myFile.FileName, pathForSaving); //如果路径不存在则新建 ImgUrl.CreateDirectory(); //保存图片 myFile.SaveAs(ImgUrl.FileAbsolutePath); isUploaded = true; //保存后的图片路径 message = ImgUrl.FileRelativePath; //缩略图处理 var thumbnailPathInfo = new ImagePathInfo(myFile.FileName, pathForSaving); using (var imgStream = myFile.InputStream) { var width = 0; var height = 0; var quality = 0; width = thumwidth; height = thumheight; quality = thumquality; using (var thumbNail = ImageHelper.GetThumbnail(imgStream, width, height, quality)) { thumbnailPathInfo.CreateDirectory(); thumbNail.Save(thumbnailPathInfo.FileAbsolutePath); } } thumbnailmessage = thumbnailPathInfo.FileRelativePath; } catch (Exception ex) { message = string.Format("File upload failed: {0}", ex.Message); } } } return(Json(new { isUploaded = isUploaded, message = message, thumbnailmessage = thumbnailmessage }, "text/html")); }