Hello,
I have a problem with the api to upload avatars.
I have a 500 error.
Here is my code :
$files = [
realpath('logo.png')
];
$postData = array(
"api_key" => API_KEY,
"api_username" => API_USERNAME,
"type" => "avatar",
"user_id" => $user_id,
"synchronous" => true
);
foreach ($files as $index => $file) {
$postData['files[' . $index . ']'] = curl_file_create(
realpath($file),
mime_content_type($file),
basename($file)
);
}
print_r($postData);
$handler = curl_init();
$headers[] = "Content-Type: multipart/form-data;";
curl_setopt( $handler, CURLOPT_URL, "https://forum.xxx.fr/uploads.json" );
curl_setopt( $handler, CURLOPT_POSTFIELDS, http_build_query( $postData ) );
curl_setopt( $handler, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $handler, CURLOPT_POST, true );
curl_setopt( $handler, CURLOPT_SSL_VERIFYPEER, false );
$response = curl_exec( $handler );
if ($debug) {
if ( $response !== false ) {
var_dump( $response );
} else {
print "Could not get a response";
}
}
Here is the answer :
Array
(
[api_key] => xxxxx
[api_username] => xx
[type] => avatar
[user_id] => 1
[synchronous] => 1
[files[0]] => CURLFile Object
(
[name] => /home/wacha/domains/domainname/public_html/logo.png
[mime] => image/png
[postname] => logo.png
)
)
{"status":500,"error":"Internal Server Error"}bool(true)
Any idea why do i have that 500 error ?
Thank you