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

tayyabshahzad1's avatar

CURL Upload Image

Hi, I am using CURL and I am receiving images in requests now I want to send data along with images to an external server via API, I am sending all data but I how will send images in API

  $file = $request->file('documents');
  				 curl_setopt_array($curl, array(
                CURLOPT_URL => '#',
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => '',
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => 'POST',
                CURLOPT_POSTFIELDS => array('DocumentType' => 'passport','DocumentFront'=> new CURLFILE('')),
                CURLOPT_HTTPHEADER => array(
                    'Authorization: Bearer '.$token
                ),
                ));
0 likes
5 replies
jlrdw's avatar

Try the php move_uploaded_file. Which laravel through symfony uses anyway.

Edit:

Of course validate first as needed.

tayyabshahzad1's avatar

@jlrdw thanks for the reply I do not want to save images into my directory I wan to upload images to external server trough API

tayyabshahzad1's avatar

@Sinnbeck thanks for sharing this BUt when I use CURL API then I am easily able to check my barer token but I guzzle response my status code is 200 but I am unable to see token in my response

Please or to participate in this conversation.