Discuz Random default Avatar

Source: Internet
Author: User

When the user does not upload their avatar in Discuz, the default avatar is displayed, then you can let this default avatar randomly display, the answer is yes, the implementation is relatively simple, if you are familiar with PHP random function rand ().

First of all to prepare a few of their own default profile picture, the size of big (200*200), Middle (120*120), Small (48*48), which is used in the back.

First, open the installed UC directory avatar.php to find the following code:

$size = In_array ($size, Array (' Big ', ' middle ', ' small '))? $size: ' Middle '; $avatar _url = "Images/noavatar_$size.gif";

Replace with:

$size = In_array ($size, Array (' Big ', ' middle ', ' small '))? $size: ' Middle '; $rand _num = rand (1,5),//using Rand () as a random function $avatar _url = ' images/randuser/'. $size. ' /'. $rand _num. gif ';

PS: $avatar _url This variable is actually the address of the Avatar, after which the assignment contains $size and $rand_num this two variables, $size will be rendered large, medium, small map corresponding big, middle, small, $rand _ Num will randomly display 1-5 of one of these numbers, so it's not hard to imagine that the address of the default avatar image will change randomly. It's easy to understand.

Next we should be based on $avatar_url this variable generated by the change of image address upload the corresponding default avatar picture, yes, here the test $rand_num is 1-5 random numbers, and look at the above path, is in the Image/randuser directory to build big, Middle and small three folders, respectively, upload 5, the size of big (200*200), Middle (120*120), Small (48*48).

The resulting default avatar image address will be as follows: Images/randuser/small/2.gif, this 2.gif may be 3.gif or 5.gif.

Reprinted from: http://www.9its.com/article-35-295-1.html

Discuz Random default 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.