Created
February 12, 2017 14:03
-
-
Save woganmay/7d339f5586e688fc0c646823ed71f8f8 to your computer and use it in GitHub Desktop.
Upload a new avatar image to Flarum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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