protected void UploadNow_Click(object sender, EventArgs eventArgs) { if (InputFile.PostedFile != null) { #region Upload file Bobs.Misc m = new Bobs.Misc(); m.UsrK = Usr.Current.K; if (CurrentPromoter != null) m.PromoterK = CurrentPromoter.K; m.DateTime = DateTime.Now; m.Folder = CurrentFolder; m.Guid = Guid.NewGuid(); if (InputFile.PostedFile.FileName.IndexOf(".") == -1) m.Extention = ""; else m.Extention = InputFile.PostedFile.FileName.Substring(InputFile.PostedFile.FileName.LastIndexOf(".") + 1).ToLower(); if (m.Extention.Equals("jpeg") || m.Extention.Equals("jpe")) m.Extention = "jpg"; if (!(m.Extention.Equals("jpg") || m.Extention.Equals("gif") || m.Extention.Equals("png") || m.Extention.Equals("flv") || m.Extention.Equals("mp4") || (Usr.Current.IsAdmin && m.Extention.Equals("zip")) || m.Extention.Equals("swf"))) throw new DsiUserFriendlyException("You can only upload gif, jpg, png, flv or swf files with this page."); m.Size = InputFile.PostedFile.ContentLength; m.Name = InputFile.PostedFile.FileName.Substring(InputFile.PostedFile.FileName.LastIndexOf("\\") + 1); byte[] bytes = new byte[InputFile.PostedFile.InputStream.Length]; InputFile.PostedFile.InputStream.Read(bytes, 0, (int)InputFile.PostedFile.InputStream.Length); if (m.Extention.Equals("jpg") || m.Extention.Equals("gif") || m.Extention.Equals("png")) { using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(bytes))) { m.Width = image.Width; m.Height = image.Height; } } if (CurrentPromoter != null) { if (m.Extention.Equals("swf")) { if (m.Size <= 150 * 1024) m.NeedsAuth = true; } } m.Update(); try { Storage.AddToStore(bytes, Storage.Stores.Pix, m.Guid, m.Extention, m, ""); } catch { m.Delete(); } if (m.NeedsAuth) { Mailer adminMail = new Mailer(); adminMail.Subject = "New files waiting to be approved!!! uploaded by" + Usr.Current.NickNameSafe; adminMail.To = "*****@*****.**"; adminMail.Body += "<p>New FILES uploaded by <a href=\"[LOGIN(" + Usr.Current.Url() + ")]\">" + Usr.Current.NickNameSafe + "</a></p>"; if (CurrentPromoter != null) adminMail.Body += "<p>... for promoter <a href=\"[LOGIN(" + CurrentPromoter.Url() + ")]\">" + CurrentPromoter.Name + "</a></p>"; adminMail.Body += "<h2>Files:</h2>"; adminMail.Body += "<p><a href=\"" + m.Url() + "\">" + HttpUtility.HtmlEncode(m.Name) + "</a> - " + m.FileSizeString + "</p>"; adminMail.TemplateType = Mailer.TemplateTypes.AdminNote; adminMail.RedirectUrl = Usr.Current.Url(); adminMail.Send(); } if (CurrentBanner != null) CurrentBanner.AssignMisc(m); #endregion if (CurrentBanner != null) Response.Redirect(CurrentBanner.Url()); else Response.Redirect(ContainerPage.Url.CurrentUrl("mode","view","misck",m.K)); } }
public Misc Duplicate() { Misc m = new Misc(); m.Guid = Guid.NewGuid(); m.Extention = this.Extention; m.Update(); try { Storage.AddToStore( Storage.GetFromStore(Storage.Stores.Pix, this.Guid, this.Extention), Storage.Stores.Pix, m.Guid, m.Extention, m, ""); m.UsrK = this.UsrK; m.PromoterK = this.PromoterK; m.Size = this.Size; m.DateTime = this.DateTime; m.DateTimeExpires = this.DateTimeExpires; m.Folder = this.Folder; m.Name = this.Name; m.Note = this.Note; m.Xml = this.Xml; m.NeedsAuth = this.NeedsAuth; m.BannerLinkTag = this.BannerLinkTag; m.BannerBroken = this.BannerBroken; m.BannerBrokenReason = this.BannerBrokenReason; m.Width = this.Width; m.Height = this.Height; m.Update(); return m; } catch (Exception ex) { m.Delete(); throw ex; } }
public static Misc UploadFile(HtmlInputFile inputFile, Usr uploadUsr, Promoter promoter, Banner banner, string folder, List<string> acceptedFileExtensions) { if (inputFile.PostedFile != null) { #region Upload file Misc m = new Misc(); m.UsrK = uploadUsr.K; if (promoter != null) m.PromoterK = promoter.K; m.DateTime = DateTime.Now; m.Folder = folder; m.Guid = Guid.NewGuid(); if (inputFile.PostedFile.FileName.IndexOf(".") == -1) m.Extention = ""; else m.Extention = inputFile.PostedFile.FileName.Substring(inputFile.PostedFile.FileName.LastIndexOf(".") + 1).ToLower(); if (m.Extention.Equals("jpeg") || m.Extention.Equals("jpe")) m.Extention = "jpg"; if (!acceptedFileExtensions.Contains(m.Extention)) { string listOfFileExtensions = ""; foreach(string s in acceptedFileExtensions) listOfFileExtensions += s + ", "; throw new DsiUserFriendlyException("You can only upload " + listOfFileExtensions.Substring(0, listOfFileExtensions.Length-2) + " files with this page."); } if (promoter != null && m.Extention.Equals("swf")) { if (m.Size <= 150 * 1024) m.NeedsAuth = true; } byte[] bytes = new byte[inputFile.PostedFile.InputStream.Length]; inputFile.PostedFile.InputStream.Read(bytes, 0, (int)inputFile.PostedFile.InputStream.Length); m.Size = inputFile.PostedFile.ContentLength; m.Name = inputFile.PostedFile.FileName.Substring(inputFile.PostedFile.FileName.LastIndexOf("\\") + 1); if (m.Extention.Equals("jpg") || m.Extention.Equals("gif") || m.Extention.Equals("png")) { using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(bytes))) { m.Width = image.Width; m.Height = image.Height; } } m.Update(); try { Storage.AddToStore(bytes, Storage.Stores.Pix, m.Guid, m.Extention, m, ""); } catch (Exception ex) { m.Delete(); throw ex; } if (promoter != null) { if (promoter != null && m.NeedsAuth) { Mailer adminMail = new Mailer(); adminMail.Subject = "New files waiting to be approved!!! uploaded by" + uploadUsr.NickNameSafe; adminMail.To = "*****@*****.**"; adminMail.Body += "<p>New FILES uploaded by <a href=\"[LOGIN(" + uploadUsr.Url() + ")]\">" + uploadUsr.NickNameSafe + "</a></p>"; if (promoter != null) adminMail.Body += "<p>... for promoter <a href=\"[LOGIN(" + promoter.Url() + ")]\">" + promoter.Name + "</a></p>"; adminMail.Body += "<h2>Files:</h2>"; adminMail.Body += "<p><a href=\"" + m.Url() + "\">" + HttpUtility.HtmlEncode(m.Name) + "</a> - " + m.FileSizeString + "</p>"; adminMail.TemplateType = Mailer.TemplateTypes.AdminNote; adminMail.RedirectUrl = uploadUsr.Url(); adminMail.Send(); } } if (banner != null) banner.AssignMisc(m); return m; #endregion } else return null; }
private Misc SaveMisc() { Misc m = new Misc(); if (uiInputFile.PostedFile.FileName.Length == 0) return m; m.Guid = Guid.NewGuid(); SetAndCheckExtension(m); m.UsrK = Usr.Current.K; m.PromoterK = int.Parse(uiPromotersAutoComplete.Value); m.DateTime = DateTime.Now; m.Size = uiInputFile.PostedFile.ContentLength; m.Name = uiInputFile.PostedFile.FileName.Substring(uiInputFile.PostedFile.FileName.LastIndexOf("\\") + 1); byte[] bytes = new byte[uiInputFile.PostedFile.InputStream.Length]; uiInputFile.PostedFile.InputStream.Read(bytes, 0, (int)uiInputFile.PostedFile.InputStream.Length); SetAndCheckWidthAndHeight(m, bytes); m.Update(); try { Storage.AddToStore(bytes, Storage.Stores.Pix, m.Guid, m.Extention, m, ""); } catch (Exception ex) { m.Delete(); throw ex; } return m; }