I'm trying to upload product images by using prestashop dev's example.
Here is my code:
$image_path = 'http://www.naminukas.lt/out/pictures/master/straipsniai/thumb/skalbimo_masinos_pelesis.jpg';
$url = 'http://46.101.240.63/api/images/products/198';
$key = 'myapicode';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_PUT, true); // Un-commet to edit an image
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);
Then I'm trying to upload with html code, it's works
<form enctype="multipart/form-data" method="POST" action="http://eWURcnNJ6mbLUHB10EEIzTZsTShs33IX@myprestahop.com/api/images/products/1">
<fieldset>
<legend>Add image for products No 1</legend>
<input type="file" name="image">
<input type="submit" value="Execute">
</fieldset>
</form>
but with curl it doesn't and getting error 66, Unable to upload this image.
Have you any ideas?
P.S: I'm using PHP 7.0 version.
You have a SSl error: https://curl.haxx.se/libcurl/c/libcurl-errors.html
Try adding these lines to ignore certificates and ssl related warnings. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);