Prestashop Web服务图像上传

时间:2018-11-23 09:55:58

标签: php web-services curl prestashop crud

您好,在此先感谢您,现在我正尝试通过网络服务将图像上传到prestashop 1.7,但无法在产品中插入图像。我不知道失败了什么,因为即使启用了调试,我也没有得到Web服务的任何响应(我得到了其余文件的xml响应,但不是来自curl的xml响应)。

变量$idProduct是传递给函数的值,并且已定义。

我的代码如下:

$url = PS_SHOP_PATH."api/images/products/".$idProduct;
$dir_path_to_save = 'img/import/';

$img_path = getFile($remoteImageURL, $dir_path_to_save);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, PS_WS_AUTH_KEY.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$img_path));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
echo print_r($response);
curl_close($ch);

getFile函数将映像下载到安装了prestashop的服务器并返回路径(返回已存储映像的真实路径的字符串,该字符串已经过测试)。

我试图制作一张表格来上传图像(仅用于测试),但是它返回"code 66 - unable to save this image"。我不知道这是否有帮助。

谢谢

更新

一个程序员的同伴告诉我使用curl_file_create()

因此,我通过以下方式更改了$img_path声明:

$img = curl_file_create($dir_path_to_save.'/'.basename($img_path));

现在一切正常。

0 个答案:

没有答案