Skip to content

Instantly share code, notes, and snippets.

@rubanraj54
Last active June 8, 2020 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubanraj54/88462661f691ea63c9269afa230306d1 to your computer and use it in GitHub Desktop.
Save rubanraj54/88462661f691ea63c9269afa230306d1 to your computer and use it in GitHub Desktop.
/**
* @param string $fileName
* @throws Exception
*/
private function postSalesDataFileToEmarsys(string $fileName): void
{
$cfile = new \CURLFile("/srv/www/app/sales_items_2020-05-26 13:50:11.csv", 'text/csv');
$ch = curl_init();
$options = array(
CURLOPT_URL => $this->csvUploadEndPoint,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => array(
'Authorization: bearer ' . $this->emarsysBearerToken,
'Content-type: text/csv',
'Accept: text/plain'
),
CURLOPT_POSTFIELDS => array(
'data-binary' => $cfile
),
CURLOPT_RETURNTRANSFER => 1
);
curl_setopt_array($ch, $options);
$result = strval(curl_exec($ch));
/**
* @var int
*/
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
//unlink($fileName);
if ($httpCode != 200) {
throw new Exception($result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment