• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Setting a user's avatar

Chris D

XenForo developer
Staff member
#2
You would need to download the image to a temporary file, then pass that in to the various default avatar functions on the avatar model which will handle the resizing, copying and ultimate setting of the new avatar.

Effectively you can use XF code for everything except the initial bit (which will involve downloading vs uploading the avatar).
 

Robust

Well-known member
#3
You would need to download the image to a temporary file, then pass that in to the various default avatar functions on the avatar model which will handle the resizing, copying and ultimate setting of the new avatar.

Effectively you can use XF code for everything except the initial bit (which will involve downloading vs uploading the avatar).
So something like this should work?

Code:
$url = 'http://example.com/image.png';
$filename = '/temp/myfolder';
file_put_contents($filename, file_get_contents($url));
There's also the simple:
copy('http://example.com/image.png','/temp/myfolder');

That requires allow_url_fopen set to true though. I can always use cURL too, which is required for my add-on anyway. Which would be the recommended method of downloading the file? And if I use the slash (/) is that relative to the XenForo installation or the root of the server?
 

Chris D

XenForo developer
Staff member
#4
More or less.

This is typically what XF does to create temporary files:
PHP:
$filename = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
 

Robust

Well-known member
#5
More or less.

This is typically what XF does to create temporary files:
PHP:
$filename = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
How do you download them initially? I don't think XF requires cURL as per the requirements page, and it doesn't explicitly ask for allow_url_fopen to be set to true. They're the only two ways I know to download files.