PDA

View Full Version : How to access avatars from filesystem?


nirvana43
03-31-2012, 11:17 AM
Hello,
When avatars are stored in database, they can be accessed by :
http://website.com/forums/image.php?u=userid
But when the avatars are moved to filesystem, how they can be accessed?
Specially when this is required in 3rd party modifications, how it can be achieved?

Cheers!!

--------------- Added 1333196792 at 1333196792 ---------------

Nevermind.. coded my own solution but if someone knows any better way to do this then please let me know.
Below is the custom function i have coded which can return avatars when they are stored in filesystem instead of database :

//Call below function for every uid
function getUserAvatar($uid = 0)
{
$adiResult = $vbulletin->db->query_read('SELECT avatarrevision from '.TABLE_PREFIX.'user where userid='.$uid);
if($row = $vbulletin->db->fetch_array($adiResult ))
{
if($row['avatarrevision'] === 0)
$adiAvatar = 'images/default_avatar_image.jpg';
else
$adiAvatar = 'customavatars/thumbs/avatar' . $uid . '_' . $row['avatarrevision'] . '.gif';
}
else
$adiAvatar = 'images/default_avatar_image.jpg';

return $adiAvatar;
}

Cheers!!

nirvana43
04-06-2012, 03:45 AM
Update..
EXIDE has also provided easy solution on this question -

vB has a function that returns the avatar URL for you.


<?php
include('./global.php');
include('./includes/functions_user.php');

$avatar = fetch_avatar_url(USERID);
/* Array
(
[hascustom] => 1
[0] => storage/avatars/avatar1_12.gif
[1] => width="80" height="80"
) */
?>


Props to EXIDE.
Cheers!!