Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

francisMS's avatar

post image to webservice using cURL in laravel

  $data = $request->bodyData;
  $fileData = image file;

I want send $data and $fileData to the webservice using cURL

Any one can help.

This is my code :

    $postfields = array();
    $postfields['data'] = $data;
    $postfields['fileData'] = $fileData;


     $ch = curl_init();

     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $output = curl_exec($ch);

     curl_close($ch);
0 likes
0 replies

Please or to participate in this conversation.