Jump to content

Webservice: Problem adding image using CURL


Recommended Posts

Hello,

I'm using this code to add a product image.

$nombre_img=$_REQUEST['imagen'];
$image_path = $_SERVER['DOCUMENT_ROOT'].'/tienda/fotos/'.$nombre_img;
$curlFile = new CURLFile($image_path,'image/jpg','image.jpg');

$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, $webServiceUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, $webServiceToken . ':'); //note token must be followed by a colon in this situation
curl_setopt($ch, CURLOPT_POSTFIELDS, ['image' => $curlFile]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
$response = curl_exec($ch);

$info = curl_getinfo($ch);

switch ($info['http_code']) {
    case 200:
       print_r($response);
     default:
        throw new \Exception($response, $info['http_code']);
        break;
}
curl_close($ch);

?>

The code is working, the image is added to the product by I can not get the" id" off the image.

$response is allways empty

 


 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...