XF 2.1 Is it possible to produce a users avatar URL from just their ID?

Rezpkt

Member
data/avatars/s/21/21944.jpg

so it looks like the 21944 is the user ID and this does correlate to the 21 folder. the s stands for small.

how does it work out the 21 folder, why not 2 or 219?

is it possible to grab the users avatar with just their ID?

thanks.
 
thanks Brogan

where is it getting the 178 directory from though? It's no coincidence my userID starts with 178
 
how does it work out the 21 folder, why not 2 or 219?
As a rule of thumb, all of the /data content files (attachments, avatars, etc.) are stored in a folder name that is the ID value divided by 1000 and then taking the 'floor' value of it. floor($this->user_id / 1000); It works out to 1,000 files per folder as Brogan mentioned.
 
Thanks Kevin & Brogan
:) If this is something you're doing inside of XF, you can use the function $User.getAvatarUrl({size}) to grab the URL where {size} would be 's' for small. In a template, for example, you could use this inline <xf:set var="$image">{$User.getAvatarUrl('s', null, true)}</xf:set> to set a variable named '$image' to get the user's avatar URL assuming that $User is your user entity. If you're working with a thread then you could use something like <xf:set var="$image">{$thread.User.getAvatarUrl('s', null, true)}</xf:set> instead.
 
:) If this is something you're doing inside of XF, you can use the function $User.getAvatarUrl({size}) to grab the URL where {size} would be 's' for small. In a template, for example, you could use this inline <xf:set var="$image">{$User.getAvatarUrl('s', null, true)}</xf:set> to set a variable named '$image' to get the user's avatar URL assuming that $User is your user entity. If you're working with a thread then you could use something like <xf:set var="$image">{$thread.User.getAvatarUrl('s', null, true)}</xf:set> instead.

Yeah, no. It would be from a SPA which knows the users user ID. I was hoping to be able to build the URL client side, which sounds like I can.
 
Top Bottom