Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: WilK on October 10, 2009, 04:23:40 PM

Title: Avatar file
Post by: WilK on October 10, 2009, 04:23:40 PM
How to determine what is the file name of avatar, while I have user ID available or avatar url.

I don't need url! I need exact file name in attachments folder or avatar directory if it is not uploaded. Second part is quite easy... but the first part is problem for me.
Title: Re: Avatar file
Post by: tyty1234 on October 10, 2009, 09:27:18 PM
You can try doing some of these via loadMemberContext().


<?php// Grab SSI.php.require('SSI.php');// Easy-to-use function to get member data.function get_memberData($memID){ global $context, $memberContext; // Load the user's profile. loadMemberData($memID, false, 'profile'); loadMemberContext($memID); $context['member'] = $memberContext[$memID]; // Put the data into an array. foreach($context['member'] as $key => $value) $member[$key] = $value; // Return the data. return $member;}// Do we have a user id defined?$user_id = isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : $context['user']['id'];// Put the data into ths variable.$memberData = get_memberData($user_id);// Read the data in the array.echo '<pre>';print_r($memberData);echo '</pre>';?>


In $memberData['avatar']['href'], you'll get the url yes, but it contains the folder that avatar is in. Unless you were looking to do it through php.
Title: Re: Avatar file
Post by: WilK on October 11, 2009, 05:09:02 AM
It's not solution for me. I can't have url - i must get direct, local path - like /home/forum/attachments/1_fc903404acc5f9af99e6d03d02e278839fa8de7b or /home/forum/avatars/somefoler/somefile.png
Title: Re: Avatar file
Post by: tyty1234 on October 11, 2009, 06:20:24 PM
Well...if you know where your avatar directory is, you can do something like this.


<?php// dirname(__FILE__) assumes this file is in the root folder of your SMF Forum.$avatar_dir = dirname(__FILE__) . '/user_avatars/';$user_avatar = $avatar_dir . basename($memberData['avatar']['href']);?>
Title: Re: Avatar file
Post by: WilK on October 11, 2009, 06:25:44 PM
Well... not exactly.

$memberData['avatar']['href'] => http://www.informatyka.stgk.eu/index.php?action=dlattach;attach=135;type=avatar

So, it will give me only download link, while I really need direct filepath with real file name :)
Title: Re: Avatar file
Post by: tyty1234 on October 11, 2009, 07:05:53 PM
Can you link me to the page with the code I provided?
Title: Re: Avatar file
Post by: WilK on October 11, 2009, 07:19:51 PM
http://www.informatyka.stgk.eu/av/

I use Imagick php extension - I don't know why code that was working, just stopped. I could use url by usinf fopen() and Imagick ReadImageFile method, but now it gives error - while using direct file name it doesn't. So that's why I can't use download link. Even /home/informatyka/www/attachments/index.php?action=dlattach;attach=135;type=avatar is not working.
Title: Re: Avatar file
Post by: tyty1234 on October 11, 2009, 07:36:26 PM
That page doesn't look like the code i provided...
Also, I use SMF 2.0 RC1.2, and all my user's avatars have an image extension (via upload form in profile)
Title: Re: Avatar file
Post by: WilK on October 12, 2009, 02:42:32 AM
Quote from: tyty1234 on October 11, 2009, 07:36:26 PM
That page doesn't look like the code i provided...
Also, I use SMF 2.0 RC1.2, and all my user's avatars have an image extension (via upload form in profile)

I needed to change a little bit your code to make path correct, beacuse the file is not in root of forum.
Rest is based on what you wrote.

I als use SMF 2.0 RC1.2 And all my user's avatars don't have image extension, they are uploaded, and have links like attachments.

EDIT:

I figured it out -  I need to make avatar folder, so avatars won't upload to attachments folder.
So rest is easy :)
Thanks.