5
PHP Curlで複数の画像をアップロードしようとしています。私が使用しているAPIは私に次の例を示します:PHP Curlで複数の画像をアップロード
{
"errors":{
"error":{
"@key":"unsupported-form-element"
}
}
}
:私はAPIからこの応答を得た
$files = array();
foreach($photos as $photo) {
$cfile = new CURLFile('../' . $photo, 'image/jpeg', 'test_name');
$files[] = $cfile;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://services.example.com/seller-api/sellers/' . $seller . '/ads/' . $voertuig_id . '/images');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $files);
curl_setopt($ch, CURLOPT_PROXY,'api.test.sandbox.example.com:8080');
curl_setopt($ch, CURLOPT_USERPWD, 'USER:PASS');
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.example.com',
'Content-type: multipart/form-data; boundary=vjrLefDejJaWiU0JzZfsadfasd1rMcE2HQ-n7XsSx',
'Accept: application/vnd.com.example.api+json'
));
$output = curl_exec($ch);
curl_close($ch);
まず:
curl -v -s -u username:password \
-H "Content-Type: multipart/form-data" \
-H "Accept: application/vnd.com.example.api+json" \
-F "[email protected];type=image/jpeg" \
-F "[email protected];type=image/jpeg" \
-XPUT 'https://example.com/api/sellers/12/ads/217221/images'
は、だから私のPHPスクリプトに私はこれを試してみました
しかし今は全く応答がありません。 複数ファイルのアップロードにカールを使用するにはどうすればよいですか?
たとえば、$ filesが空のJSONの場合、エラーはまったくなく、画像を返します(ofcourseは空です)。
これは私が使用しているAPIのドキュメントです: https://services.mobile.de/manual/new-seller-api.html#_upload_images
EDIT: を私がリクエストボディを構築し、それを送信しようとしたが、それは何もしません。
$requestBody = '';
$requestBody .= '--vjrLeiXjJaWiU0JzZkUPO1rMcE2HQ-n7XsSx\r\n';
$requestBody .= 'Content-Disposition: form-data; name="image"; filename="ferrari.JPG"\r\n';
$requestBody .= 'Content-Type: image/jpeg\r\n';
$requestBody .= 'Content-Transfer-Encoding: binary\r\n';
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);