Upload pictures, ask pictures 200100 pixels, size and less than 2m

xiaoxiao2021-03-06  113

Upload pictures, ask pictures 200100 pixels, size is less than 2m, if the picture does not meet the requirements, can not upload, otherwise the image is uploaded, and the picture is dynamically named by the system date, reserves the path to the database.

private void Button1_Click (object sender, System.EventArgs e) {if (File1.PostedFile.ContentType.ToUpper () IndexOf ( "IMAGE")> -. 1) {System.Drawing.Image img = System.Drawing.Image.FromStream (File1.postedfile.inputstream); int width = img.width; int Height = img.height; if (width> 200 || Height> 100 || File1.postedFile.ContentLength> 1024 * 1024 * 2) {response.write ("Do not: width =" width.toString () "
Height =" height.toString () "
size =" (this.file1.postedfile.contentLength / 1024) .tostring ( "##, ## 0.00") "k");} else {string spath = server.mappath (system.datetime.now.tostring ("YYY-MM-DD HH-MM-SS") session.SessionID ".jpg"); this.file1.postedfile.saveas (spath); Response.write ("Save Success");}} else {response.write ("Please select a picture file!");}}

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

New Post(0)