upload picture

xiaoxiao2021-03-06  121

Image uploaded database section (automatically generated)

Www.chinacs.net 2002-2-15 Chinese C # Technology Station

Public Int FepicDataSet (String String String String String String StrPicintro, String Strthumbnail, int OPID)

{

// string strPicTitle, // string strPicDate, // string strPicName, // int intPicType, // string strPicIntro, // string strPicName, // string strThumbnail, // int opIDSqlConnection myConnection = new SqlConnection (ConfigurationSettings.AppSettings [ "ConnectionString "]); Sqlcommand mycommand = new sqlcommand (" MAG_FEPICDATASET ", MyConnection); // Mark the command as a sprocmycommand.commandtype = commandType.StoredProcedure;

// add parameters to sprocsqlparameter parameterUserid = New SqlParameter ("@ OPID", SqldbType.InT); parameterUserId.value = OPID; mycommand.parameters.add (parameterUserid);

SQLParameter ParameterPictitle = New SqlParameter ("@ pictitle", sqldbtype.char, 30); parameterPictitle.Value = strpictitle; mycommand.parameters.add (parameterPictitle);

Sqlparameter parameterpicdate = new sqlparameter ("@ picdate", sqldbtype.char, 10); parameterpicdate.value = strpicdate; mycommand.parameters.add (parameterpicdate);

Sqlparameter parameterpicname = new sqlparameter ("@ picname", sqldbtype.char, 50); parameterpicName.Value = strpicname; mycommand.Parameters.add (parameterpicname);

Sqlparameter parameterpictype = new sqlparameter ("@ Pictype", sqldbtype.int); parameterPictype.Value = intPictype; mycommand.Parameters.add (parameterpictype);

SqlParameter parameterPicIntro = new SqlParameter ( "@ picIntro", SqlDbType.Char, 255); parameterPicIntro.Value = strPicIntro; myCommand.Parameters.Add (parameterPicIntro); SqlParameter parameterThumbnail = new SqlParameter ( "@ thumbnail", SqlDbType.Char, 50) Parameterthumbnail.value = strand.Parameters.Add (parameterthumbnail);

SqlParameter parameterHostAddress = new SqlParameter ( "@ opIP", SqlDbType.Char, 15); parameterHostAddress.Value = Context.Request.UserHostAddress; myCommand.Parameters.Add (parameterHostAddress);

// SqlParameter parameterRID = new SqlParameter ( "@ returnID", SqlDbType.Int); // parameterReturnUserID.Value = -1; // parameterRID.Direction = ParameterDirection.Output; // myCommand.Parameters.Add (parameterRID);

// Execute the command in a try / catch to catch duplicate username errorstry {// open the connection and execute the commandmyConnection.Open (); mycommand.executenon query ();} catch {

// failed to create a new userreturn -1;} finally {

// Close the connectionif (myConnection.State == ConnectionsState.Open) myconnection.close ();}

Return 1;

}

Image uploaded codeBehind (自动 自动)

Www.chinacs.net 2002-2-15 Chinese C # Technology Station

Using system;

Using system.collections;

Using system.componentmodel;

Using system.configuration;

Using system.data;

Using system.drawing;

Using system.Web;

Using system.Web.SessionState;

Using system.Web.ui;

Using system.Web.ui.webcontrols;

Using system.Web.ui.htmlcontrols;

Using system.text;

Using cj168.util;

Namespace CJ168.Web.mag.admins.Fedata {///

/// summary description for fedata./// public class feputPic: system.web.ui.page {protected system.web.ui .WebControls.TextBox txtboxPicTitle; protected System.Web.UI.WebControls.Calendar calPicDate; protected System.Web.UI.WebControls.DropDownList ddlPicType; protected System.Web.UI.WebControls.TextBox txtboxPicIntro; protected System.Web.UI.HtmlControls .HtmlInputFile filePicName; protected System.Web.UI.WebControls.Button btnSubmit; protected System.Web.UI.WebControls.Label lblPicInfo; protected System.Web.UI.WebControls.TextBox txtboxPicDate; protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1; protected System.Web.UI.WebControls.RegularExpressionValidator vldCatName; protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2; protected System.Web.UI.WebControls.CustomValidator CustomValidator1; protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionVali dator1; protected System.Web.UI.WebControls.HyperLink hlkOriPic; protected System.Web.UI.WebControls.HyperLink hlkNewPic; protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator2; protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator3; protected System.Web.UI.WebControls.CheckBoxList checkboxlistRewrite; private void Page_Load (object sender, System.EventArgs e) {// Put user code to initialize the page here // if (Page.IsPostBack) // txtboxPicDate.Text = calPicDate .Selecteddate.toString ();

IF (! page.ispostback) {bind2dropdownlistPictype ();

// for (int i = 0; i

}

public void Bind2DropDownListPicType () {cj168.DataAccess.Admins admins = new cj168.DataAccess.Admins (); DataSet ds = admins.FePicTypeGet (); // ddlPicType.DataSource =; DataView dv = new DataView (ds.Tables [ "PicType "]); DATAROWVIEW DRV = DV.AddNew (); // DatacolumnView DCV = DV.AddNew (); DRV [" Title "] =" Please select "; DRV [" fepictypeid "=" 0 "; drv.endedit ();

Dv.Sort = "fepictypeid";

DDLPICTYPE.DASOURCE = DV;

DDLPICTYPE.DATABIND ();

Public void UploadFile (Object Sender, System.EventArgs E) {

string imgNameOnly, imgNameNoExt, imgExt; string imgThumbnail; int erroNumber = 0; System.Drawing.Image oriImg, newImg; string strFePicSavePath = ConfigurationSettings.AppSettings [ "FePicSavePath"] ToString ();. string strFePicThumbFormat = ConfigurationSettings.AppSettings [ "FePicThumbFormat" .] .ToString () ToLower (); int intFeThumbWidth = Int32.Parse (ConfigurationSettings.AppSettings [ "FePicThumbWidth"]); string fileExt; string strPicTitle = txtboxPicTitle.Text; string strPicIntro = txtboxPicIntro.Text; string strPicDate = txtboxPicDate.Text ;

int intPicType = Int32.Parse (ddlPicType.SelectedItem.Value); string strPicType = intPicType.ToString () "_" DateTime.Now.Date.ToShortDateString () "_"; string strFePicWebPath = ConfigurationSettings.AppSettings [ "FePicWebPath "];

CJ168.DataAccess.admins admins = new cj168.dataaccess.admins ();

//if(admins.Fepictypesett (TEXTBOXTILE.TEXT, 0) <0) // lbladdpicinfo.text = "Operation failed: There is already the same name type, please modify"; // else // lbladdpicinfo.text = "successful" ;

Stringbuilder Picinfo = New StringBuilder ();

IF (page.isvalid) {

For (int i = 0; i errors : file (" (i 1) ") " IMGNAMEOME " already exists, please modify the file name
");}}}} else {erronumber = erronumber 1; if (fileext == "") Picinfo.append (" error: Please select file
"); elsePicinfo.append (" error: file (" (i 1) ")" IMGNAMEONLY "extension" fileext "Not licensed
");

}

IF (Erronumber> 0) {picinfo.append (" all the operations are not completed, please modify the error, then perform
");

Hlkoripic.imageurl = ""; hlkoripic.tooltip = ""; hlknewpic.imageURL = "; hlknewpic.tooltip =";} else {for (int i = 0; i

HttpPostedFile PostedFile = Request.Files [i]; imgNameOnly = strPicType System.IO.Path.GetFileName (PostedFile.FileName); imgNameNoExt = System.IO.Path.GetFileNameWithoutExtension (PostedFile.FileName); imgExt = System.IO.Path. GetExtension (postedfile.filename) .tostring (). TOLOWER ();

oriImg = System.Drawing.Image.FromStream (PostedFile.InputStream); newImg = oriImg.GetThumbnailImage (intFeThumbWidth, intFeThumbWidth * oriImg.Height / oriImg.Width, null, new System.IntPtr (0)); switch (imgExt) {/ / case ".jpeg": case ".jpg": oriImg.Save (strFePicSavePath imgNameOnly, System.Drawing.Imaging.ImageFormat.Jpeg); break; case ".gif": oriImg.Save (strFePicSavePath imgNameOnly, System. Drawing.Imaging.ImageFormat.Gif); break; case ".png": oriImg.Save (strFePicSavePath imgNameOnly, System.Drawing.Imaging.ImageFormat.Png); break;} // oriImg.Save (ConfigurationSettings.AppSettings [ " FepicsavePath "] IMGNAMENOEXT " .jpg ", System.drawing.Imaging.ImageFormat.jpeg);

switch (strFePicThumbFormat) {// jpeg format can get the smallest file size, and the png is the largest size // case "jpeg": case "jpg": newImg.Save (strFePicSavePath imgNameOnly "_thumb.jpg", System .Drawing.Imaging.ImageFormat.Jpeg); imgThumbnail = imgNameOnly "_thumb.jpg"; break; case "gif": newImg.Save (strFePicSavePath imgNameOnly "_thumb.gif", System.Drawing.Imaging.ImageFormat.Gif ); imgThumbnail = imgNameOnly "_thumb.gif"; break; case "png": newImg.Save (strFePicSavePath imgNameOnly "_thumb.png", System.Drawing.Imaging.ImageFormat.Png); imgThumbnail = imgNameOnly "_thumb .png "; break; default: newImg.Save (strFePicSavePath imgNameOnly " _thumb.jpg ", System.Drawing.Imaging.ImageFormat.Jpeg); imgThumbnail = imgNameOnly " _thumb.jpg "; break;

} // switch

Picinfo.append (" file name: " ImgnameOnly "(" Oriimg.Width ")" PostedFile.ContentLength / 1024 "KB
"); picInfo.Append (" thumbnail name: " imgThumbnail " ( " newImg.Width " x " newImg.Height ")

"); HLKORIPIC.IMAGEURL = STRFEPICWEBPATH IMGNAMEOMEONLY : " PostedFile.ContentLength / 1024 " KB "; hlkNewPic.ImageUrl = strFePicWebPath imgThumbnail; hlkNewPic.ToolTip =" ◆ thumbnail ◆ / n filename: " imgThumbnail " / n size: " newImg.Width "x" newimg.height;

Oriimg.dispose (); newimg.dispose (); picinfo.append (" image upload success
"); if (Admins.FepicDataSet (StrPictitle, Strpicdate, ImgnameOnly, IntPictype, Strpicintro, imgthumbnail, 0) <0) Picinfo.append (" save information to database failed
"); ElsePicinfo.append (" saving information to database Success
");

} // for picinfo.append (" all operations" "" "");

} // if erronumber = 0

} else {picinfo.append (" has an error, please check. Operation is not successful
);

Hlkoripic.imageurl = ""; hlkoripic.tooltip = ""; hlknewpic.imageURL = ""; hlknewpic.tooltip = "

}

For (int i = 0; i

}

Public void caldateselected (object sender, system.eventargs e) {txtboxpicdate.text = CalpicDate.selectedDate.toshortdateString ();

}

public void ServerValidateCheckDate (object sender, System.Web.UI.WebControls.ServerValidateEventArgs value) {cj168.util.iUtil iUtils = new cj168.util.iUtil (); if (! iUtils.IsDate (value.Value)) value.IsValid = false; elsevalue.issalid = true;

}

#Region Web Form Designer Generated CodeOverride Protected Void OnNit (Eventargs E) {//// Codegen: This Call is Required by The ASP.NET Web Form Designer./initializationComponent ();Base.onInit (E);

///

/// Required Method for Designer Support - Do Not Modify ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////> System.EventHandler (this.page_load);

} #endregion}}}

Image uploaded WebForm (自动 自动)

Www.chinacs.net 2002-2-15 Chinese C # Technology Station

<% @ Page language = "c #" codebehind = "feuploadpic.aspx.cs" autoeventwireup = "false" inherits = "cj168.web.mag.admins.Fedata.FeuploadPic"%>

<% @ Register tagprefix = "cj168" tagname = "header" src = "Modules / Headerfe.ascx"%>

fedata </ ​​title></p> <p><meta content = "Microsoft Visual Studio 7.0" Name = "Generator"></p> <p><meta content = "c #" Name = "code_language"></p> <p><meta content = "javaScript" name = "vs_defaultclientscript"> <meta content = "http://schemas.microsoft.com/intellisense/ie5" name = "vs_targetschema"></p> <p><style> body {font-size: 9pt}</p> <p>.calpicdate {font-size: 9pt; font-family: Verdana, Helvetica, Sans-Serif}</p> <p>.valid {font-size: 9pt; color: red}</p> <p>TD {font-size: 9pt}</p> <p></ style></p> <p></ HEAD></p> <p><body ms_positioning = "gridLayout"></p> <p><Table Width = "100%"></p> <p><tr></p> <p><TD> <CJ168: Header ID = "Header1" runat = "server"> </ cj168: header> </ td></p> <p></ TR></p> <p></ TABLE></p> <p><form id = "fedata" method = "post" encType = "multipart / form-data" runat = "server"></p> <p><Table ID = "Table1" Cellspacing = "0" cellpadding = "1" width = "750" border = "1"></p> <p><Tr></p> <p><TD Width = "70"> Photo Title </ TD></p> <p><TD> <asp: textbox id = "txtBoxPictitle" runat = "server"> </ asp: textbox> <br></p> <p><Asp: requiredfieldvalidator id = "Requiredfieldvalidator1" runat = "server" ErrorMessage = "Please fill out the picture of the title." CssClass = "valid" ControlToValidate = "txtboxPicTitle"> </ asp: requiredfieldvalidator> <br></p> <p><ask: regularExpressionValidator ID = "VldcatName" ErrorMessage = "picture title at least 2 characters, should not contain '" "! @ # $% ^ & * () <>" "{} []?,? ¥" CssClass = "Valid" ControlTovAlidate = "txtBoxPictitle" ValidationExpression = "[^ '^" ^ "^ / ^! ^ ^ ^ # ^ $ ^% ^ / ^^ & ^ * ^ (^) ^ <^> ^" ^ " ^? ^. ^, ^? ^ ^ ^ / {^ /} ^ /] [^ /]] {2,} "runat =" server "> </ asp: regularExpressionValidator> </ td> </ tr></p> <p><Tr></p> <p><TD> Picture Date </ TD></p> <p><TD> <asp: textbox id = "txtBoxPicdate" runat = "server" width = "300> </ ask: textbox> <ask: calendar id =" calpicdate "runat =" server "cssclass =" CalpicDate "width = "300" SelectMonthtext = "This month" selectWeektext = "this week" nextprevformat = "fullmonth" OnseChanged = "Caldateelected"></p> <p><NextPrevStyle Cssclass = "Calpicdate"> </ nextprevstyle></p> <p><WeekendDayStyle Forecolor = "Red"> </ weekenddayStyle></p> <p><TodayDayStyle Font-bold = "true" forcolor = "red" backcolor = "# ccccff"> </ TodayDayStyle></p> <p><SelectedDayStyle Backcolor = "Black" font-bold = "true"> </ successddtystyle></p> <p></ asp: calendar> <br></p> <p><Asp: requiredfieldvalidator id = "Requiredfieldvalidator2" runat = "server" ErrorMessage = "Please select or fill in the date of the picture." CssClass = "valid" ControlToValidate = "txtboxPicDate"> </ asp: requiredfieldvalidator> <br></p> <p><Asp: customvalidator id = "CustomValidator1" ErrorMessage = "is not a valid date format" CssClass = "valid" ControlToValidate = "txtboxPicDate" Runat = "server" OnServerValidate = "ServerValidateCheckDate"> </ asp: customvalidator> </ TD> </ TR></p> <p><Tr></p> <p><TD> Picture Classification </ TD></p> <p><TD> <asp: dropdownlist id = "ddlPicType" runat = "server" DataValueField = "fePicTypeID" DataTextField = "Title"> </ asp: dropdownlist> <FONT face = "Arial"> </ FONT> <asp: regularexpressionvalidator id = "RegularExpressionValidator1" ErrorMessage = "choose image classification" CssClass = "valid" ControlToValidate = "ddlPicType" ValidationExpression = "[^ 0] {1,}" Runat = "server"> </ asp: regularexpressionvalidator> </ TD ></p> <p></ TR></p> <p><Tr></p> <p><TD> Picture Introduction </ TD></p> <p><TD> <asp: textbox id = "txtBoxPicintro" runat = "server" maxlength = "255" textmode = "multiline" columns = "50" rows = "5"> </ asp: textbox></p> <p><Asp: RegularExpressionValidator id = "Regularexpressionvalidator2" Runat = "server" CssClass = "valid" ErrorMessage = "content should not contain '<>" ControlToValidate = "txtboxPicIntro" ValidationExpression = "[^' ^ <^>] {0, } "> </ asp: regularExpressionValidator></p> <p></ Td></p> <p></ TR></p> <p><tr></p> <p><TD COLSPAN = "2"> (Support File Format: JPG, GIF, PNG) </ TD></p> <p></ TR></p> <p></ Table></p> <p><Table cellspacing = "0" width = "750" border = "1"></p> <p><tr></p> <p><td width = "70"> Picture name </ td> <TD width = "300"> <input title = "Browse" TYPE = "file" size = "25" name = "filepicname" runat = "server" ID = "FilePICname"></p> <p><Asp: RegularExpressionValidator id = "Regularexpressionvalidator3" Runat = "server" CssClass = "valid" ErrorMessage = "filename only by letters or numbers, can not contain - and other symbols _ length is at least 1" ControlToValidate = "filePicName" ValidationExpression = "[: .// A-ZA-Z0-9] {1,}"> </ ask: regularExpressionValidator></p> <p></ td></p> <p><Td> <asp: checkboxlist id = "checkboxlistRewrite" runat = "server" BorderWidth = "0" Height = "100%" CellPadding = "5" RepeatLayout = "Table" RepeatColumns = "1" RepeatDirection = "Vertical"></p> <p><ask: ListItem value = "1"> Overwrite original picture </ asp: listitem></p> <p></ asp: checkboxlist> </ td></p> <p></ TR></p> <p></ table></p> <p><Table cellspacing = "0" width = "750" border = "1"></p> <p><Tr></p> <p><TD align = "middle"> <ask = "btnsubmit" οnclick = "UPLOADFILE" runat = "server" text = "OK"> </ asp: button> </ td></p> <p></ TR></p> <p><Tr></p> <p><TD> <asp: label id = "lblpicinfo" runat = "server"> label </ ask: label> </ td></p> <p></ TR></p> <p><Tr></p> <p><TD> <font face = "Song"> </ font></p> <p></ Td></p> <p></ TR></p> <p></ table></p> <p></ form></p> <p><asp: hyperlink id = "hlkoripic" runat = "server"> original image </ asp: hyperlink></p> <p><asp: hyperlink id = "hlknewpic" runat = "server"> thumbnail </ asp: hyperlink> </ body></p> <p></ Html></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-100082.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="100082" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.036</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '7pFAA4usFEUwcP_2FArONTMm4CqBru1if_2BFI47wx9lkI90SNnPoez_2BBAyUsal9NlS5XJQh2J7_2FOtELI5pFMdpdVA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>