Files() from $site or $page

Hello there,

When I add a PDF file to the content folder via PHP and then var_dump the files of $site or $page, it seems the files() is empty. Looks like $site and $page vars fetch the content during page load.

How do I access the PDF file through “files()”?
How do I “refresh” the $site or “$page” variable?

The code is in the controller:

<?php
require_once('vendor/autoload.php');


return function($kirby, $pages, $page, $site) {
...
$pdf->Output('content/voucher/' . $pdfName, 'F');
...
var_dump($page->files());
...
$pdf->Output('content/voucher/' . $pdfName, 'F');

is what creates the file?

Have a look at File::create() | Kirby CMS to create the file as object in the Kirby context. This will also ensure to add it to the relevant collections (like $page->files()).

1 Like

@distantnative

I add this file::create code below the code “$pdf->output”? (with adjusted params)

$pdf->Output('content/voucher/' . $pdfName, 'F');

$file = File::create([
  'source'     => kirby()->root('assets').'/images/some-image.jpg',
  'parent'     => page('photography')->children()->listed()->first(),
  'filename'   => 'new-image.jpg',
  'template' => 'cover',
  'content'   => [
    'caption'   => 'A nice view from above',
  ]
]);