我對PHP CURL很新穎,並試圖調用API來執行圖像上傳(一次有多個文件)。 API文檔在CURL中給出了下面的例子。我已經測試過,它正在工作。圖像上傳CURL命令到PHP捲曲
curl -H "Authorization: Bearer 123456789" -i -X POST -F "whitespace=1" \
-F "imageData[][email protected]/path/to/images/milk.jpg" \
-F "imageData[][email protected]/path/to/images/peas.jpg" \
https://mytestapi.com/1.0/uploadimages
現在我需要將它轉換爲PHP Curl。出於某種原因,我總是收到錯誤「imageData」參數無效。是否有人可以幫助
$token = '123456789';
$imgUrl = 'https://mytestapi.com/1.0/uploadimages';
$data_to_post = array();
$data_to_post['whitespace'] = '1';
$data_to_post['imageData[]'] = '@/path/to/images/milk.jpg';
$data_to_post['imageData[]'] = '@/path/to/images/peas.jpg';
$curl = curl_init($imgUrl);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Authorization: Bearer '.$token]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl,CURLOPT_POST, 1);
curl_setopt($curl,CURLOPT_POSTFIELDS, $data_to_post);
$data = json_decode(curl_exec($curl));
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
var_dump($data);
人將你給的賞金 –
感謝賞金將文件上傳。如果您想讓 –