I need to do the following using PHP curl:
curl "https://the.url.com/upload"
-F file="@path/to/the/file"
-F colours[]="red"
-F colours[]="yellow"
-F colours[]="blue"
The code I have tried:
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'file' => curl_file_create($file),
'colours' = ['red','yellow','blue']
]);
$response = curl_exec($ch);
But I just get an error 'Array to string conversion in... (the colours line)'. If I remove the colours entirely then it works but I need to include them.
I have tried putting the post fields array in http_build_query() but then the server returns '415 Unsupported Media Type'. I'm guessing because it's missing a mime type (the file is a custom binary file).
I have also tried...
'colours[1]' = 'red'
'colours[2]' = 'yellow'
'colours[2]' = 'blue'
But the server returns an error saying colours must be an array. It's as though I need to create an associative array but with duplicate keys... which I know I can't do.
Can anyone help?