Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to modify nicknames in php code

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to modify nicknames in php code. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Php code to modify the nickname method: 1, find the picture format; 2, save the file in the project server; 3, get configuration information; 4, verify the reference sdk and upload the picture to the server, update the avatar nickname.

This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.

Easily implement the modification of avatar nickname in the source code of PHP live broadcast platform

Auroral push and auroral IM are often used in the source code development of php LVB platform to achieve message push and real-time communication. If you need to update user information and other functions, many friends will find that how to update the database information will only update the database information, and will not be synchronously updated to the aurora server?

So let's talk about it next. If aurora SDK is connected to the source code of PHP LVB platform, how to update aurora user profile picture and nickname.

The basic steps are as follows:

1. Format of uploaded image: png,jpg or jpeg

2. Upload the updated picture and save it in the specified directory of the server where the project is located.

3. Cite relevant information such as aurora sdk, upload pictures with known directories to aurora, and update user profile photos

First, first of all: make sure that the uploaded picture format needs to meet the requirements of the aurora avatar, specifically look for the aurora picture format, the format used here is png,jpg or jpeg.

Step 2: save the file on the server where the project is located, with the following code:

$image = $_ FILES ['file']; / / set the upload path. I put it in the source code of PHP LVB platform. Under the jmessage directory under upload (you need to set folder permissions for interview in linux) if ($image [' name']! =') {$type = strrchr ($image ['name'], "."); $path = ". / public/jmessage/". $image ['name']; / / determine whether the uploaded file is in the image format if (strtolower ($type) = =' .png'| | strtolower ($type) = = '.jpg' | | strtolower ($type) = = '.jpeg') {/ / move the image file to the directory move_uploaded_file ($image ['tmp_name'], $path);} else {$this- > error (' upload the picture with the suffix png,jpg or jpeg');}}

Step 3: get the aurora configuration information, here we store it in a unified configuration information table

$configpri=getConfigPri (); $app_key = $configpri ['jpush_key']; / / Aurora key$master_secret = $configpri [' jpush_secret']; / / Aurora secret

4. Verify that the aurora sdk is referenced and upload the image to the aurora server, and update the profile picture and nickname. The source code of the PHP live broadcast platform is set as follows

If ($app_key & & $master_secret) {Vendor ("JMessage.autoload"); $jm = new\ JMessage\ JMessage ($app_key, $master_secret); $user = new\ JMessage\ IM\ User ($jm); $username = $id; / / auroral user name if ($image ['name']! =') {$rescource = new\ JMessage\ IM\ Resource ($jm); / / upload the image to Aurora $response = $rescource- > upload ('image', $path) / change Aurora platform user's name profile $respon=$user- > update ($username, ['nickname'= > "nickname you want to update",' avatar'= > $response ['body'] [' media_id']]); unlink ($path); / / Delete local picture} else {/ / change Aurora platform user's name $respon=$user- > update ($username, ['nickname'= > "nickname you want to update]]) } / / query user information, which can be printed to check whether the update was successful $userinfo = $user- > show ($username);} $this- > success ('modified successfully');} else {$this- > error ('modification failed');}

Note: variable data values such as configuration information in the above code can be adjusted according to the needs of the project.

At this point, the function of updating the profile picture and nickname of the aurora user is complete.

This is the end of the article on "how to modify nicknames in php code". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report