Phpcms User modified Avatar

Source: Internet
Author: User

Do the project user's avatar is present ucenter inside, phpcms through Phpsso This single-point login system? Specific I also do not know, Phpcms comes with the V9_member table does not store the user picture field, if need to modify, will modify the avatar in the Ucenter,

Read the user picture in Phpcms, also need to Phpsso, through it to link ucenter to get avatar.

So how to pass in the PHPCMS controller, you can modify the user picture.

The first is divided into two parts: 1. Upload the avatar, and save it. 2. Create a thumbnail of the saved avatar and create a thumbnail at the specified location.

After the generated thumbnail, the uploaded avatar is useless, can be deleted, generated thumbnails are used when the avatar display (very mosaic)

The code is as follows:

1. File upload function saveimage,2. Edit Profile function edit_myself () (change avatar here), 3. Generate thumbnails at the specified location Do_upload_avatar () The return value is the path to the thumbnail, 4. Initialize Phpsso

/* File Upload * @param type $file $_files[' image ') * @param int $max _file_size upload file size limit, unit byte * @param string $     Img_folder Upload file path * @param int $imgpreview whether to generate a preview map (1 is generated, others are not generated); * @param type $imgpreviewsize thumbnail scale * @return string picture path **/public function saveimage ($file, $max _file_siz E = 500000, $img _folder = "uploadfile/", $imgpreview = 0, $imgpreviewsize = "1/3") {//upload avatar and save, prepare the Avatar for change profile//            The picture extension is set $uptypes = Array (' image/jpg ', ' image/jpeg ', ' image/png ', ' image/gif ', ' image/bmp ');            $file 1 = $_files["Image1"][tmp_name];//temporary file $filename = $file ["Tmp_name"]; $pinfo = PathInfo ($file ["name"]); Array $ftype = $pinfo [' extension '];            File extension//Var_dump ($ftype); exit;                    if (!is_uploaded_file ($file ["Tmp_name"]) {//whether there is a file echo "picture does not exist!";            Exit            }//$file = $_files["Image1"]; if ($max _file_size &Lt            $file ["Size"]) {//Check file size//echo "File too big!";            Exit                    } if (!in_array ($file ["type"], $uptypes) {//Check file type echo "file type does not match!". $file ["type"];            Exit            } if (!file_exists ($img _folder)) {mkdir ($img _folder); } $img = $img _folder. Time (). Rand (1,100). "." .     $ftype;            Picture path plus picture name has a timestamp and random number so you do not have to verify the file name, if you can have duplicate, I am very helpless ah.            if (file_exists ($img)) {//echo "file with the same name already exists";            Exit                    } if (!move_uploaded_file ($filename, $img)) {echo "Error moving File";            Exit            }//Echo $img; exit;    return $img; }public function Edit_myself () {//Edit profile used to upload avatar $userid = Param::get_cookie (' _userid '); $username =$_post[' username ']; $this->mem = Pc_base::load_model (' Member_model '); $res = $this->mem->select (Array (' userid ' =$userid), "Phpssouid"), $phpssouid = $res [0][' Phpssouid ']; $avator =get_memberavatar ($phpssouid);//var_dump ($avator) ; exit;//echo "<pre>";//Var_dump ($_post);    echo "<br>";//var_dump ($_files); Exit;//var_dump ($res _save); exit; Uploadimg/1494923496.jpgif ($_files[' avator ' [' Name ']!= ') {$res _save= $this->saveimage ($_files[' avator ']); Ava = $this->do_upload_avatar ($phpssouid, $res _save); Save Avatar}//var_dump ($ava), exit;if ($username) {$mem = $this->mem->update (Array (' nickname ' = = $username), array (' userid ' = $userid)); } $this->personal ();} Private Function Do_upload_avatar ($phpssouid, $avatarurl) {//The uploaded avatar is saved as Phpsso's solo map folder and generates thumbnails//echo "--1-----1"; exit;/ /processing folder start//According to the user ID to the folder name $dir1 = Ceil ($phpssouid/10000); $dir 2 = ceil ($phpssouid% 10000/1000);//Create Picture Storage Folder//Here hard code, picture forced to save stored in SSO $avatarfile = Phpcms_path. ' phpsso_server/uploadfile/avatar/'; $dir = $avatarfile. $dir 1. ' /'. $dir 2. ' /'. $phpssouid. ' /'; $avatar _url = App_path. ' phpsso_server/uploadfile/avatar/'. $dir 1. ' /'. $dir 2.'/'. $phpssouid. ' /';//Echo $avatarfile;D: \workspace\project\shaimobao\phpsso_server/uploadfile/avatar///echo "-----------";//Echo $dir;D: \workspace\project\shaimobao\phpsso_server/uploadfile/avatar/3/1/20750///echo "--------";//Echo $avatar _ url;http://www.cms.localhost/phpsso_server/uploadfile/avatar/3/1/20750///exit;if (!file_exists ($dir)) {// Create folder based on ID mkdir ($dir, 0777, true);}     Processing folder End$arr_url = Parse_url ($avatarurl);//Echo 1111;//var_dump ($arr _url); exit; Path ' Uploadimg/1494923821.jpg$filename = substr ($arr _url[' path '],0,1) = = '/'? substr ($arr _url[' path '],1): $arr _url [' Path ']; $filename = substr ($arr _url[' path '],0,1) = = ' \ \ '? substr ($arr _url[' path '],1): $arr _url[' path '];//echo $ filename;exit;//uploadimg/1494923821.jpg$filename = Phpcms_path. $filename,//echo $filename//d:\workspace\project\shaimobao\uploadimg/1494923889.jpgif (!file_exists ($filename)) return;//generates thumbnail pc_base::load_sys_class (' image ', ' ', ' 0 '), $image = new Image (1,0), $image->thumb ($filename, $dir. ' 30x30.jpg ', $image->thumb ($filename, $dir. ' 45x45.jpg ', (), $image->thumb ($filename, $dir. ' 90x90.jpg ', 90, 90); $ Image->thumb ($filename, $dir. ' 180x180.jpg ', in the $AA = $image->thumb ($filename, $dir. ' 480x480.jpg ', 480, 480); $this->_init_phpsso () $status = $this->client->ps_updateavatar ($phpssouid); $avatar = $avatar _url. ' 480x480.jpg '; if (file_exists ($filename)) {//delete temporary files, keep only thumbnail unlink ($filename);} return $avatar;} /** * Initialize Phpsso * About Phpsso, include client and client Configure * @return string Phpsso_api_url Phpsso address */private Fun Ction _init_phpsso () {pc_base::load_app_class (' client ', ' member ', 0);d efine (' APPID ', pc_base::load_config (' system '), ' Phpsso_appid '); $phpsso _api_url = pc_base::load_config (' System ', ' Phpsso_api_url '); $phpsso _auth_key = pc_base:: Load_config (' System ', ' Phpsso_auth_key '); $this->client = new Client ($phpsso _api_url, $phpsso _auth_key); return $ Phpsso_api_url;}

Phpcms User modified Avatar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.