I'm writing a script to uploading images to a specific api. Uploading one image is not a problem but more than one. The API documentation says the following:
curl -v -s -u username:password \
-H "Content-Type: multipart/form-data" \
-H "Accept: application/vnd.de.xxx.api+json" \
-F "[email protected];type=image/jpeg" \
-F "[email protected];type=image/jpeg" \
-XPUT 'https://services.xxx.de/seller-api/sellers/123/ads/123/images'
My script:
$ch = curl_init();
$images = array(
'image' => new CURLFile('PATH\1.jpg', 'image/jpeg', 'image')
);
curl_setopt($ch, CURLOPT_URL, 'https://services.xxx.de/seller-api/sellers/123/ads/123/images');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $images);
curl_setopt($ch, CURLOPT_USERPWD, 'USERNAME:PASSWORD');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Host: services.xxx.de',
'Content-Type: multipart/form-data',
'Accept: application/vnd.de.xxx.api+json'
));
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
The problem is that the api delete other images if I'm uploading a new one. But I can't write an array with multiple same keys like that:
$images = array(
'image' => new CURLFile('PATH\1.jpg', 'image/jpeg', 'image'),
'image' => new CURLFile('PATH\2.jpg', 'image/jpeg', 'image')
);
So the question is how I can set multiple CURLFiles with the same index like the curl command in the documentation?