Thinkphp changes the Avatar foreground & lt; formaction = & quot ;__ URL _/user_upimgs & quot; method = & quot; post & quot; enctype = & quot; multipart/form-data & quot; & gt; & nbsp; & nb thinkphp modify the Avatar
Front-end
Background
Function user_upimgs (){
Import ("ORG. Net. UploadFile ");
$ Upload = new UploadFile (); // instantiate the upload class
$ Upload-> maxSize = 3145728; // sets the attachment upload size.
$ Upload-> allowExts = array ('jpg ', 'GIF', 'PNG', 'jpeg '); // you can specify the attachment upload type.
$ Upload-> saveRule = uniqid ;//
$ Upload-> savePath = './Public/Uploads/'; // sets the attachment upload Directory
If (! $ Upload-> upload () {// upload error message
$ This-> error ($ upload-> getErrorMsg ());
} Else {// the uploaded file is successfully obtained.
$ Info = $ upload-> getUploadFileInfo ();
}
// Save the form data, including the attachment data
$ User = M ("users"); // instantiate the User object
$ User-> create (); // create a data object
$ User-> user_upimg = 'uploads/'. $ info [0] ["savename"]; // Save the uploaded photo and assemble it as needed
// $ User-> fenxiang_ SC = 'uploads/'. $ info2 [0] ["savename"];
$ Imgs = D (); // write user data to the database
$ Imgs-> query ("update users set user_upimg = 'uploads /". $ info [0] ["savename"]. "'Where users_id = '". $ _ POST ['users _ id']. "'");
$ This-> success ("data is saved successfully! ");
}