目前,从本地文件夹POST图像我使用curl和PHP,这是我的代码:
$url = 'http://myprestashop.com/api/images/products/1';
$image_path = 'C:\\my_image.png';
$key = 'My web service key';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $key.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
如何从URL(http://imageserver.com/image.jpeg)而不是本地文件夹(C:\ my_image.png)发布图像?有可能吗?
答案 0 :(得分:-1)
只需更改图片路径并尝试使用此代码。
$url = 'http://myprestashop.com/api/images/products/1';
$data = array('key' => 'My web service key', 'image_path' => '@/home/user/test.png');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);