public ActionResult MailerImages()
        {
            var files = Request.Files;

            List <string> paths = new List <string>();

            if (files != null && files.Count > 0)
            {
                for (int i = 0; i < files.Count; i++)
                {
                    string dfolder = DateTime.Now.Date.ToString("ddMMyyyy");

                    string fsave = "~/PIC/" + dfolder;

                    bool exists = System.IO.Directory.Exists(Server.MapPath(fsave));

                    if (!exists)
                    {
                        System.IO.Directory.CreateDirectory(Server.MapPath(fsave));
                    }
                    try
                    {
                        ImageUpload imageUpload = new ImageUpload()
                        {
                            isSacle    = true,
                            Width      = 1000,
                            UploadPath = fsave
                        };
                        MemoryStream target = new MemoryStream();
                        files[i].InputStream.CopyTo(target);
                        byte[] data = target.ToArray();

                        var imageResult = imageUpload.RenameUpload(data, ".png");

                        if (imageResult.Success)
                        {
                            paths.Add("/PIC/" + dfolder + "/" + imageResult.ImageName);
                        }
                    }
                    catch
                    {
                        return(Json(new { id = 1, msg = "Image upload to fail" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }

            return(Json(new { id = 0, data = paths }, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        private string UploadImage(HttpPostedFileBase img, string path, string extension)
        {
            if (img != null)
            {
                MemoryStream target = new MemoryStream();
                img.InputStream.CopyTo(target);
                byte[] data = target.ToArray();

                ImageUpload imageUpload = new ImageUpload
                {
                    Width      = 500,
                    isSacle    = false,
                    UploadPath = "~" + path
                };

                ImageResult imageResult = imageUpload.RenameUpload(data, extension, 0);

                if (imageResult.Success)
                {
                    return(path + "/" + imageResult.ImageName);
                }
            }
            return("");
        }