Created
December 20, 2017 22:51
-
-
Save cidicles/dfa574f2c33184d5a3c5df953807e3cd to your computer and use it in GitHub Desktop.
Parse SCV with Php & Insert into API
This file contains hidden or 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
<?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