Skip to content

Instantly share code, notes, and snippets.

@cidicles
Created December 20, 2017 22:51
Show Gist options
  • Save cidicles/dfa574f2c33184d5a3c5df953807e3cd to your computer and use it in GitHub Desktop.
Save cidicles/dfa574f2c33184d5a3c5df953807e3cd to your computer and use it in GitHub Desktop.
Parse SCV with Php & Insert into API
<?php
$row = 1;
if (($handle = fopen("collection_ejs.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
$post = array(
'name' => $data[1],
'locale' => 'en_us',
'attributes' => '{}'
);
$url = 'http://localhost:1337/collection/en_us/1/1';
$ch = curl_init($url);
$postString = http_build_query($post, '', '&');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
}
fclose($handle);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment