Hello,
I want to upload a media with the api with php.
Upload a media with postman is actually working but when I try to do it in php, I always get a Filetype not allowed
error :
[“files”]=>
array(1) {
[0]=>
object(stdClass)#5671 (4) {
[“name”]=>
string(15) “1536761420-4641”
[“size”]=>
int(0)
[“type”]=>
string(19) “multipart/form-data”
[“error”]=>
string(20) “Filetype not allowed”
}
}
My code, inpired by this implementation:
$file = file_get_contents($filepath);
//$file = fopen($filepath, ‘r’);
$body = array(
‘multipart’ => [
[
‘name’ => ‘name’,
‘contents’ => ‘API upload test’
],
[
‘name’ => ‘files’,
‘contents’ => $file
]
],
‘headers’ => array(“Authorization” => "Bearer ".$token, “Content-type” => “multipart/form-data”),
);
$response = wp_remote_post( get_option(‘xibo_cms_api_url’) . ‘/library’, $body );
In this code, I use wordpress customs functions but I’ve tried without in a alone php file using this as base and I had the same error.
Do you have a idea of what I’m doing wrong ?
Thanks,
Adrien