[RESOLVED]How to resize image when upload and make bigger the time allow to run scripts

Hi, i got 2 problems

First problem, when users try to upload photos bigger than 1,5 MB i would love to resize the photo to be max 1,5 MB, how to do?

this is the code i use to upload a picture :

if (file != null)
                    {
                        if (file.ContentLength > 0)
                        {

                            var myuploadextension = Path.GetExtension(file.FileName);

                            if (myuploadextension.ToUpper() == ".JPEG" || myuploadextension.ToUpper() == ".JPG" || myuploadextension.ToUpper() == ".BMP" || myuploadextension.ToUpper() == ".PNG" || myuploadextension.ToUpper() == ".GIF")
                        {


                            var sizeMb = (file.ContentLength / 1024f) / 1024f; //file.contentlength is in bytes

                            var todaydate = DateTime.Now.ToShortDateString();
                            var todaydatefriendly = todaydate.ImageFriendly();
                            var myuploadiwthoutextension = Path.GetFileNameWithoutExtension(file.FileName);
                            var myuploadiwthoutextensionfriendly = myuploadiwthoutextension.ImageFriendly();
                            var UserId = User.Identity.GetUserId();

                            var fileName = todaydatefriendly + "-" + UserId + "-" + myuploadiwthoutextensionfriendly + myuploadextension;

                            var path = Path.Combine(Server.MapPath("~/Content/UserCreations"), fileName);
                            file.SaveAs(path);
                            

                            creation.CreationPhotoBis = fileName; 

                            db.Creations.Add(creation);
                            db.SaveChanges();



                        }


                        }
                    }

Second problem, if this upload action tak more the certain time i got a message that i go over my allowed tim for script, how to avoid it? or make this time bigger when upload?

Somebody can help me to implement this code?

Thanks

Leave a Reply