Ok, so I have a .env variable CSV_FILE=~/sites/computer-availability/storage/app/WAV_SUM.csv
I want to load it into my controller so that I can parse it into an array. I tried env("app.CSV_FILE"); but that just gives me a string of the file path. Not what I'm wanting. I need the files contents.
How could I go about loading the data from the CSV file using the .env variable?
I have tried the following
$csv_data = Storage::get(env("WAV_SUM.csv");
$csv_data = env("app.CSV_FILE");
$csv_data = config("app.CSV_FILE");
This is from the official php documentation and slightly altered
<?php
$row = 1;
$csv = getenv('app.CSV_FILE');
$csv = str_replace("~/sites/computer-availability/","",$csv);
if (($handle = fopen($csv, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.