Is there a way to create a file with a .vcf extension and store it inside the corresponding content folder?
I have a function that generates a file with the page information. But I have no idea how I can save it in the folder.
Route:
site/controllers/card.php
Code:
<?php
return function ($page) {
$name = $page->name();
$email = $page->email();
$phone = $page->phone();
function generate_vcard(){
// Code that I already have solved
}
$vCard = generate_vcard();
/*
How can I store the vCard file that
I generate with my function in the content folder?
*/
return [
'vCard' => $vCard
];
};
?>
May I ask why you are doing this in your controller? This will try to create this file every time the page is loaded, while you only need to recreate the file when the content changes. So it would make more sense to do this within page.update: after hook.
OK you are right. Thank you very much for the observation and response. I will review the event page.update:after that you indicate to adapt the solution to my code.
Do you know if there is any way to indicate that the file is created, it is stored in the directory of the active page?
Do you really need a file? Or do you want people just to be able to download it?
I did a .vcf download recently: VCF / Vcard generation in template
You can link to a virtual file and it triggers the vcf template to generate a vcf with the latest data from the page.