I am developing a simple plugin that allows for an admin to edit a CSV and then a normal user to be able to view the table and generate quotes from the prices stored in the table etc.
Everything works including the two pages (shown by shortcode hooks), the form shows and at the moment we just return a 0 value but obviously when the CSV can be accessed then we can start generating quotes as we can grab the value from the table.
My problem is that when I use the following code to push the CSV into an Array, it doesn't seem to work and I'm not entirely sure why. Apologies for the bad formatting, I'm a messy coder while things aren't working - I promise I'll fix it later!
$csvData = file_get_contents('products.csv');
$lines = explode(PHP_EOL, $csvData);
$array = array();
foreach ($lines as $line) {
$array[] = str_getcsv($line);
}
If I were to print then I just get 'Array', and if I were to write the code to print the entirety of the Array, I get nothing either.
On a standalone PHP test it works, but in WordPress it doesn't seem to. I've only been doing WP development since yesterday afternoon so this side of things is quite new to me. Once then CSV can be handled as an Array then I can complete the quoting algorithm.
Also, one quick question, is this the best way to handle data? I was toying with the idea of an SQL database but I want the whole plugin to be self contained, so I've opted for a CSV to exist within the plugins folder.
EDIT: when I delete the plugin, the CSV is under the 'files to be deleted' section, so it is being uploaded and does exist alongside the functional PHP file.