I'm sure this question has been asked many times, but I can't figure out why my php script is not working. I have a CSV file that I know it works flawlessly when I upload it using the following command line curl:
curl -H 'Content-Type: text/csv' --data-binary @/Users/johndoe/Downloads/payables.csv -H "Authorization: Bearer [some_token_key]" 'https://example.com/api/v1/imports.json'
And here's my php script when I tried to translate this command into PHP Curl:
$file = "/Users/johndoe/Downloads/payables.csv";
$authorization = "Authorization: Bearer [some_token_key]";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://example.org/api/v1/imports.json");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, [$authorization, 'Content-Type: text/csv']);
$cfile = new CurlFile($file, 'text/csv');
$data = array('data-binary' => realpath($cfile));
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$curl_response = curl_exec($curl);
curl_close($curl);
Does anyone see what's wrong with my PHP script? I'm using php 5.5, and the error that I see on the receiving site that tries to process the CSV file is that it can't find the the CSV import headers. This doesn't make any sense. Any ideas?