Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Upload a new avatar image to Flarum
<?php
// See: https://gist.github.com/woganmay/4c15a0f7c16e41ab3a3ea1a73c595bf9
$api_url = sprintf("https://my.flarum.site/api/users/%s/avatar", $user->id);
// See: https://gist.github.com/woganmay/88f15e96fc019657a0e594366403b5cf
$token = $session->token;
$avatar_file = "/storage/avatars/1234.jpg"; // Absolute path preferred
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'User-Agent: Opera/9.80 (Windows NT 6.2; Win64; x64) Presto/2.12.388 Version/12.15',
'Content-Type: multipart/form-data',
'Authorization: Token ' . $token
]);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'avatar' => curl_file_create($avatar_file, 'application/octet-stream', 'avatar')
]);
$result = curl_exec($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.