繁体   English   中英

来自URL的PHP​​ curl发布图像

[英]PHP curl post image from URL

当前,要从本地文件夹发布图像,请使用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)发布图像? 可能吗?

只需更改您的图像路径并尝试此代码即可。

$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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM