Last active
June 8, 2020 14:56
-
-
Save rubanraj54/88462661f691ea63c9269afa230306d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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