Image Upload Features and Web.config Settings (自动)

xiaoxiao2021-03-05  33

Program code: Function: 1. Upload the picture file (JPG GIF PNG), 2. Save to the specified path (set the path in Web.config, save the original format of the file), 3. And automatically generate a specified width (set width in web.config) 4. And specify format (specify the format of the thumbnail in web.config, support GIF, JPG, PNG) 5. The same thumbnail with the original map (the height of the width and high calculation of the original) 6. You can determine if files 7 already exist. If it is not overwritten, an error 8 is given. If you select "Overwrite the original picture" Checkbox, you can override the original image. 9. You can set more than 1 File INPUT and the corresponding Checkbox 10 on WebForm as required. After completion of the file, the file name, size, byte, and 11 of the original map are displayed. The file name size of the thumbnail, and 12. Display the original graphs and thumbnails. 13. Thumbnail file name format, so as to manage: big picture (original): picture classification code _ picture representative date _ picture original file name. Original format (such as: 28_2002-1-28_test.jpg) Thumbnail: Image Category Code _ Image Representative Date _ Picture Original File Name. Original Format_thumb. Specify the thumbnail format (eg 28_2002-1-28_test.jpg_thumb.gif) ----------- ----------- Web.config file:

...

... ... // fepicsavePath Image Save the actual path on the server

// FepicWebPath's network path for displaying a picture

// FepICthumbWidth thumbnail width

//

Image Upload portion of the database (automatically generate thumbnail) program code: public int FePicDataSet (string strPicTitle, string strPicDate, string strPicName, int intPicType, string strPicIntro, string strThumbnail, int opID) {// string strPicTitle, // string strPicDate, // string strPicName, // int intPicType, // string strPicIntro, // string strPicName, // string strThumbnail, // int opID SqlConnection myConnection = new SqlConnection (ConfigurationSettings.AppSettings [ "ConnectionString"]); SqlCommand myCommand = new SqlCommand ( "mag_FePicDataSet", myConnection); // Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure; // Add Parameters to SPROC SqlParameter 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", SQ lDbType.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 = strThumbnail; myCommand.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 errors try {// Open the connection and execute the Command myConnection.Open (); MyCommand.executenonQuery ();} catch {// failed to create a new user return -1;} finally {// close the connection if (myConnection.State == ConnectionsState.Open) myconnection.close ();} returnit 1; } The code upload code code code: use system; using system.collections; using s ystem.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; use system.text; using cj168.util; namespace cj168.web.mag.admins.Fedata {///

/// Summary description for fedata /// public class feUploadPic:. 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 RegularExpressionValidator1; protected System.Web.UI.WebControls.H yperLink 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.DataSource = 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; st ring 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.FePicTypeSet(textboxTitle.Text,0) <0) // lblAddPicInfo.Text = " Operation failure: There is already the same name type, please modify "; // else // lbladdpicinfo.text =" Successful operation "; StringBuilder Picinfo =

New stringbuilder (); if (page.isvalid) {for (int i = 0; i

");}} else {erronumber = erronumber 1; if (fileext ==") Picinfo.append ("

Error: Please select a file

"); Else Picinfo.append ("

Error: Document (" (i 1) ") " IMGNAMEONLY " extension " fileext " is not licensed

");}} if (erronumber> 0) {picinfo.append ("

All operations are not completed, please modify the error, then operate

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

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 imgnameonly; hlkoripic.tooltip =" ◆ original picture ◆ n file name: " ivnameonly " N Size: " Oriimg.Width " x " Oriimg.height " n bytes : " PostedFile.ContentLength / 1024 " KB "; hlkNewPic.ImageUrl = strFePicWebPath imgThumbnail; hlkNewPic.ToolTip =" ◆ ◆ n thumbnail file name: " 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 the database failed

"); Else Picinfo.append ("

Save information to the database success

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

All operations success

");} // if erronumber = 0} else {picinfo.append ("

There is a mistake, please check. Operation is not successful "); hlkoripic.imageurl =" "; hlkoripic.tooltip =" "; hlknewpic.imageURL ="; hlknewpic.tooltip = ";} for (int i = 0; i

/// Required method for Designer support - do not modify /// the contents of this method with the code editor /// private void InitializeComponent () {this.Load = new System.EventHandler (this.Page_Load);}. #ENDREGON}} Image upload WebForm code: <% @ 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

Body {font-size: 9pt}

.calpicdate {font-size: 9pt; font-family: Verdana, Helvetica, Sans-Serif}

.valid {font-size: 9pt; color: red}

TD {font-size: 9pt}

Original image

Thumbnail

转载请注明原文地址:https://www.9cbs.com/read-37954.html

New Post(0)