图像上传CURL命令到PHP Curl

图像上传CURL命令到PHP Curl,第1张

概述我是 PHP CURL的新手,并试图调用API来进行图像上传(一次多个文件). API文档在CURL中给出了以下示例.我已经测试过,它正在运行. curl -H "Authorization: Bearer 123456789" -i -X POST -F "whitespace=1" \ -F "imageData[]=@/path/to/images/milk.jpg" \ -F "ima 我是 PHP CURL的新手,并试图调用API来进行图像上传(一次多个文件). api文档在CURL中给出了以下示例.我已经测试过,它正在运行.
curl -H "Authorization: Bearer 123456789" -i -X POST -F "whitespace=1" \ -F "imageData[]=@/path/to/images/milk.jpg" \ -F "imageData[]=@/path/to/images/peas.jpg" \ https://mytestAPI.com/1.0/uploadimages

现在我需要将其转换为PHP Curl.出于某种原因,我总是得到错误“imageData”param无效.有人可以请帮助

$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,CURLOPT_POSTFIELDS,$data_to_post);$data = Json_decode(curl_exec($curl));$responseCode = curl_getinfo($curl,CURliNFO_http_CODE);curl_close($curl);var_dump($data);
解决方法 尽量给出完整的图像路径而不是’@ / path / to / images / milk.jpg’;

这是更新的代码:

$token = '123456789';$imgurl = 'https://mytestAPI.com/1.0/uploadimages';$data_to_post = array();$data_to_post['whitespace'] = '1';$data_to_post['imageData'][] = "@".$imgurl.'/path/to/images/milk.jpg';$data_to_post['imageData'][] = "@".$imgurl.'/path/to/images/peas.jpg';$curl = curl_init($imgurl);curl_setopt($curl,CURliNFO_http_CODE);curl_close($curl);var_dump($data);

如果这不起作用,请告诉我.

总结

以上是内存溢出为你收集整理的图像上传CURL命令到PHP Curl全部内容,希望文章能够帮你解决图像上传CURL命令到PHP Curl所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1032929.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存