0

I'm trying to upload a .csv file to an API. The API documentation says to post it like this:

   curl --user username:password
    --request POST
    --data-binary @yourfile.csv
    https://api.example.com/api

This works perfectly.

in PHP I have it like this:

    $data = array('myfile' => 'myfile.csv');
    $curl = curl_init('https://api.example.com/api');
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_USERPWD, "username" . ":" . "password");
    $result = curl_exec($curl);
    echo $result;

The results do equal what the API documentation says is the correct response (and is the same response as when using the command line) however it does not actually upload the contents of the file.

is my PHP structure correct? Thanks.

user2029890
  • 2,493
  • 6
  • 34
  • 65

0 Answers0