I am trying to develop a code so that each user can upload an image and have it show on their profile as their background. I have had some success using CCK Imagefield and the following code in my page.tpl.php file.

 $mybg=  $content_profile->get_variable('uprofile', 'field_background');
print '<div style="background:url(/sites/default/files/userbgs/'.arg(1).'/'.$mybg[0]['filename'].') ;">' 

With this code when a user uploads a picture and looks at their own profile everything looks great. However, if user 1 uploads a picture called xxx.jpg and user 2 uploads a picture called yyy.jpg... when user 1 goes to look at users 2 profile the code tries to look for the file xxx.jpg rather than yyy.jpg.

How can I modify the code so that it looks for the image associated with the profile that's being viewed and not image belonging to the person viewing the profile?

Thank in advance to all who read/ can help!