massimopasquali Posted March 10, 2021 Share Posted March 10, 2021 Hello, I'm trying to import a new image using webservice. The problem is that the webservice fails to create the folder and image of the cover but succes to create the folder and file about second image. I'm using the same code that we found at thi urlhttps://devdocs.prestashop.com/1.7/webservice/tutorials/advanced-use/image-management/#using-an-html-form this is my code. can you suggest me ? Tnx in advance. // invio il link alla webservice $urlImage = "https://********/api/images/products/" . $id_product . "/"; $key = '*******************************************'; //Here you set the path to the image you need to upload $image_path = $PHOTO_LINK; $image_mime = 'image/jpg'; $name_image = basename($PHOTO_LINK); // folder on the app's server $image_path = $_SERVER["HOME"]."/web/********/api/object/img_tmp/" . $name_image; // copy image to server directory from remote if(copy($PHOTO_LINK, $image_path) == true){ $args['image'] = new CurlFile($image_path, $image_mime); $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLINFO_HEADER_OUT, 1); curl_setopt($ch, CURLOPT_URL, $urlImage); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_USERPWD, $key.':'); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data_exec = curl_exec($ch); //$errno = (curl_errno($ch)); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); switch ($httpCode) { case 200: echo($response); default: throw new \Exception($response, $info['http_code']); } curl_close($ch); if (file_exists($image_path)) { //unlink($image_path); } } Link to comment Share on other sites More sharing options...
Bllidz Posted March 11, 2021 Share Posted March 11, 2021 Forum Français ici 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