コード例 #1
0
        public string Upload(HttpPostedFileBase File, string w_pacode)
        {
            if (File != null && File.ContentLength > 0)
            {
                string   filename = " ";
                decimal  filesize = 1000048;
                string[] arr      = new string[3] {
                    "jpg", "gif", "png"
                };


                filename = File.FileName;
                int Position = filename.LastIndexOf(".");
                filename = filename.Substring(Position + 1);

                if (File.ContentLength > filesize)
                {
                    return("");
                }
                else if (!arr.Contains(filename.ToLower()))
                {
                    return("");
                }
                else
                {
                    filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + Guid.NewGuid() + "_" + w_pacode + "." + filename;
                    string targetfolder = Server.MapPath(ConfigurationManager.AppSettings["StoryPicPath"] + filename);
                    Bitmap origImage    = new Bitmap(File.InputStream);
                    Image  img          = (Image)origImage;
                    img = ImageResizeHelper.ImageResize(origImage, 680, 383, false, false);
                    Bitmap newImage = new Bitmap(img);
                    //File = ImageResizeHelper.ImageResize(File, 183, 136, false, false);
                    newImage.Save(targetfolder);
                    //File.SaveAs(targetfolder);
                    return(filename);
                }
            }
            else
            {
                return("");
            }
        }
コード例 #2
0
        public ActionResult Upload(HttpPostedFileBase File, string STARS_ID, string w_pacode)
        {
            if (File != null && File.ContentLength > 0)
            {
                string   filename = " ";
                decimal  filesize = 1000048;
                string[] arr      = new string[3] {
                    "jpg", "gif", "png"
                };


                filename = File.FileName;
                int Position = filename.LastIndexOf(".");
                filename = filename.Substring(Position + 1);

                if (File.ContentLength > filesize)
                {
                }
                else if (!arr.Contains(filename.ToLower()))
                {
                }
                else
                {
                    ProfileBL profile = new ProfileBL();
                    filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + Guid.NewGuid() + "_" + w_pacode + "." + filename;
                    string targetfolder = Server.MapPath(ConfigurationManager.AppSettings["UploadPath"] + filename);
                    Bitmap origImage    = new Bitmap(File.InputStream);
                    Image  img          = (Image)origImage;
                    img = ImageResizeHelper.ImageResize(origImage, 200, 200, false, false);
                    Bitmap newImage = new Bitmap(img);
                    //File = ImageResizeHelper.ImageResize(File, 183, 136, false, false);
                    newImage.Save(targetfolder);
                    //File.SaveAs(targetfolder);
                    profile.SaveProfilUploadImage(filename, STARS_ID);
                }
            }
            return(RedirectToAction("LBCProfile", "BrandChampion"));
        }