I am currently creating a CSV file programmatically and then adding it to Kirby using File::create()
. Is there a better way to do this? Is there any way to create a file without an existing source?
File::create()
requires a source file to be provided. Is there a way to create a file without an existing source? kirby/src/Cms/FileActions.php at eb47158e91e74184ab291ede020664f1d2829f74 · getkirby/kirby · GitHub
Could be there a way with using F::write
?
kirby()->impersonate('kirby');
$csvFilePath = kirby()->root('content') . '/file-csv.csv';
$csvFile = fopen($csvFilePath, 'w');
foreach ($data as $row) {
fputcsv($csvFile, $row);
}
fclose($csvFile);
$file = File::create([
'source' => $csvFilePath,
'parent' => site(),
'filename' => date(format: 'd-m-Y H:i:s') . '-file-csv.csv',
'template' => 'csv'
]);