qhe Posted June 26, 2013 Share Posted June 26, 2013 (edited) I have two weeks testing and looking for documentation but I can not do it. I have prestashop 1.5.4.1 and use this code from Chapter 9 - Image management. It works to add images but not modify: I want to change the image 33 of the product 9 with a new image <?php define('PS_SHOP_PATH', 'http://myhost.com/testshop/api/images/products/9/33'); // id_product = 9 id_image = 33 (33.jpg) define('PS_WS_AUTH_KEY', 'RNOLmy key'); $img=$_SERVER["DOCUMENT_ROOT"].'/testshop/img/tmp/newimagefor33.jpg'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, PS_SHOP_PATH); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_PUT, true); // Un-commet to edit an image . I do it curl_setopt($ch, CURLOPT_USERPWD, PS_WS_AUTH_KEY.':'); curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$img)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); ?> It does not work (does nothing) <?php define('PS_SHOP_PATH', 'http://myhost.com/testshop/api/images/products/9/33'); // id_product = 9 id_image = 33 (33.jpg) define('PS_WS_AUTH_KEY', 'RNOLmy key'); $img=$_SERVER["DOCUMENT_ROOT"].'/testshop/img/tmp/newimagefor33.jpg'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, PS_SHOP_PATH); //curl_setopt($ch, CURLOPT_POST, true); //<--- I comment this curl_setopt($ch, CURLOPT_PUT, true); // Un-commet to edit an image curl_setopt($ch, CURLOPT_USERPWD, PS_WS_AUTH_KEY.':'); curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$img)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); ?> It does not work. What am I doing wrong? Is there another way? Could delete the image and then add it back. Anyone know how to delete an existing image using the api? Thank you very much. Regards, Quim Edited June 26, 2013 by qhe (see edit history) Link to comment Share on other sites More sharing options...
vivekgajjar Posted September 21, 2013 Share Posted September 21, 2013 Hi If the image is a jpg try to change the POSTFIELDS bit of the code From: curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path)); To: curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path.';type=image/jpg')); Vivek Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now