Setting a user's avatar

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).
 
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?
 
More or less.

This is typically what XF does to create temporary files:
PHP:
$filename = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
 
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.
 
Top Bottom