'How can I upload in one form a file and send 2 post selects from html to php and upload the file to a rest api

I am building a application in php and this is the form that i have built:

This is the html form

 <form method="POST" action="verifystate.php" enctype="multipart/form-data" >
    <select class="form-select" aria-label="Default select example" name="xxx">
    <option selected>Selectati aaa</option>
    <option>U</option>
    <option>C</option>
    </select>
    <select class="form-select" aria-label="Default select example" name="yyy">
    <option selected>Selectati bbb</option>
    <option >1111</option>
    <option >188</option>
    <option >7243</option>
    </select>
    <div class="input-group mb-3">
    <span class="input-group-text" id="inputGroup-sizing-default">Serial</span>
    <input type="text" class="form-control" aria-label="Sizing example input" aria- 
 describedby="inputGroup-sizing-default" id="serial" name="serial" value="200">
    </div>
     File: <input type="file" name="file"><br><br>
      <br/>
      <input type="submit" value="submit"  name="submit">
    </form>

This is the php script that processes the file:

<?php

$fileContent = file_get_contents($_FILES['file']['tmp_name']);
//echo $fileContent;

$standard = $_POST['standard'];
//echo $standard;

//post request to upload api 

$url = 'http://restapiurl? 
     standard=' . _POST[yyy] . '&cif=' . $_POST['xxx'];
//The URL that you want to send your XML to.

//Initiate cURL
$curl = curl_init($url);

$headers = [
    "Content-Type: text/xml",
    "serial_certificate:" . $_POST['serial']
];

//Set the Content-Type to text/xml.
//curl_setopt ($curl, CURLOPT_HTTPHEADER, array("Content-Type: text / xml","certificate:200"));
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//Set CURLOPT_POST to true to send a POST request.
curl_setopt($curl, CURLOPT_POST, true);

//Attach the XML string to the body of our request.
curl_setopt($curl, CURLOPT_POSTFIELDS, $fileContent);

//Tell cURL that we want the response to be returned as
//a string instead of being dumped to the output.
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

//Execute the POST request and send our XML.
$result = curl_exec($curl);

//Do some basic error checking.
if (curl_errno($curl)) {
    throw new Exception(curl_error($curl));
}

//Close the cURL handle.
curl_close($curl);

//Print out the response output.
echo $result;

?>

I searched on the internet but found nothing new... i included the headers the xml file in the body the api rest url address is correct. I am a newbie in PHP so if you can help me I would be very happy. The problems is that the echo $result does not return anything. It should return a number



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source