Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.

Reading from a File

Vladimir Jimenez edited this page Jun 5, 2015 · 1 revision

PhpSoda always submits all of its data to Socrata as JSON but upsert() and replace() can "deal" with more formats.

Handling JSON

Reading from a file

Uploading data from a JSON file is as simple as calling PHP's file_get_contents() and storing it in a variable.

$json = file_get_contents("path/to/dataset.json");

$ds->upsert($json);

Handling CSV

PhpSoda doesn't handle CSV internally but it does provide a CSV to JSON conversion by using the CsvConverter class.

Reading CSV from a string

If you have CSV stored in a string, pass it to a new CsvConverter instance and then pass that instance to the dataset object.

$csv = new CsvConverter($csvString);

$ds->upsert($csv);

Reading from a CSV file

To read from a file, you may use the static function fromFile() and then pass it to the dataset object.

$csv = CsvConverter::fromFile("path/to/dataset.csv");

$ds->upsert($csv);

Clone this wiki locally