我正在使用一个API,希望以下Curl上传图片:
curl https://api.example.com/vehicles/7e59591f-c5a3-974e-e452-2951040ae4ee/images \
-X POST \
-H "X-AS24-Version: 1.1" \
-H "Accept-Language: en-GB" \
-H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW" \
-H "Authorization: Bearer e7c00b24-9f5f-4909-88de-38f8d7ca08bf" \
-F "file=@foto.jpg"
现在我希望我的PHP脚本从外部URL上传图像以上传图像。但我无法让它发挥作用。
这是我的代码:
$url = 'https://api.example.com/vehicles/' . $vehicleId . '/images';
$args['file'] ='@http://www.example.com/foto.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-AS24-Version: 1.1',
'Accept-Language: en-GB',
'Content-type: multipart/form-data',
'Authorization: Bearer ' . $access_token
));
$output = curl_exec($ch);
curl_close($ch);
return $output;
我根本没有回应。 我做错了什么,或者甚至可以从网址上传?