Front Code:
/* Modify Avatar */ //upload function _sc () { $ (". Ckfile"). html (""). CSS ("Color", "#535353"); $ ("#_userImgPath"). Val (""); var str = $ ("#file"). Val (); if ($.trim (str) = = "") { $ (". Ckfile"). HT ML ("Please select File. "). CSS (" Color "," red "); return false; } else { &NBS P var postfix = str.substring (Str.lastindexof (".") + 1). toUpperCase (); if (postfix = = "JPG" | | postfix = = "JPEG" | | postfix = = "PNG" | | postfix = = "GIF" | | Postfix = = "BMP") { $ (' #showimg '). attr (' src ', ' Images/loadin G.gif '). attr ("title", "Upper Crossing, please later ..."); &nbsP var path = "Upload/userimg"; $.ajaxfileupload ({ URL: '/upload.aspx?path=upload| Userimg&shape=100*100 ', Secureuri:false, fileelementid: ' file ', &NB Sp dataType: ' text ', Success:function (msg) { if (msg.lastindexof path) = 1) { &NB Sp $ (". Ckfile"). HTML (msg). CSS ("Color", "red"); &N . Bsp Else { &NBS P $ (' #showimg '). attr (' src ', msg). attr ("title", "My Avatar"); $ ("#_userImgPath") . val (msg); } &NB Sp } / }); } else { &NBSP ; $ (". Ckfile"). HTML ("file format error. "). CSS (" Color "," red "); return false; } } background code: using System; using System.Collections.Generic; using System.Linq; using system.web; using System.Web.UI; using System.Web.UI.WebControls; using SS. Upload; using WFC. Fenxiao; namespace Wanfangcheng { Public partial class Upload:basepage & nbsp; { //File size 1024x768 Private long size = 1024; //File type private String type = ". Jpg|. Jpeg|. Png|. Gif|. BMP "; //Save name String name = ""; //save path private string path = @ "Upload/userimg"; //Save size private string shape = "100*100"; &nbsP protected void Page_Load (object sender, EventArgs e) { httpfilecollection files = request.files; if (Files! = null && files. Count > 0) { &NB Sp Name = BaseRole.Instance.UserId.ToString (); if (request.querystring["size"]! = null) { s ize = Convert.ToInt32 (request.querystring["size"]); &NB Sp if (request.querystring["path"]! = null) { &nbs P &NBSP Path = request.querystring["path"]. ToString (). Trim (). Replace (' | ', '/'); &NB Sp if (request.querystring["name"]! = null) { &nbs P name = request.querystring["Name"]. ToString (). Trim (); &NB Sp if (request.querystring["shape"]! = null) { &NB Sp shape = request.querystring["shape"]. ToString (). Trim (); &NB Sp Uploadmethod (files); } } //<summary> &N bsp; //upload images //</summary> //<param name= "HC" ></param> public void Uploadmethod (Httpfilecoll Ection hc) { Httppostedfile _file = hc[0 ]; //File size long _size = _file. ContentLength; if (_size <= 0) {  ; Response.Write ("File error. "); Response.End (); return; } if (size * 1024x768 < _size) &N Bsp { Response.Write ("File too large, maximum limit is" + Size + "KB. "); Response.End (); return; } //filename   ; string _name = _file. FileName; //file format string _tp = System . Io. Path.getextension (_name). ToLower (); if (type. IndexOf (_TP) = =-1) { &NBS P Response.Write ("file format is incorrect. "); Response.End (); return; } //save path &nbs P String _path = HttpContext.Current.Server.MapPath (path) + @ "/" + name + _tp; Try { int w = Convert.ToInt32 (shape. Split (' * ') [0]); int h = convert.toint32 (shape. Split (' * ') [1]); Imagehelper.cutforcustom (_file, _path, W, H, 50); Response.Write (path + @ "/" + name + _TP); } catch (Exception) { Response. Write ("Oops, something went wrong.") "); Response.End (); { } } }
ASP. NET-based Ajaxfileupload.js for file asynchronous uploads