Url of file shows to media folder

I used to get a “clean” url to a pdf to download like this:
example.xyz/page/flyer.pdf

But now it generates the link to the media folder like this:
example.xyz/media/pages/page/1572027225-1547672525/flyer.pdf

Is this correct or how can I get a clean url ?

<?php if($pdf = $page->flyer()->toFile()): ?>
  <a href="<?= $pdf->url() ?>" target="_blank">Download Pdf</a>
<?php endif ?>

Thanks a lot

This is correct because all public files are now stored in the media folder.

Ok thanks a lot for the info !
But would there be a way to achieve this with a workaround ?

Maybe it would be possible with a custom URL and the router, but I haven’t actually tried that out yet.

Ok no problem thanks for the tip, I might look into that then some time. :slightly_smiling_face:

I have a related issue, the url() of the file returns the media folder. But the file i’m loading is a css with an @font-face inside with relative path like font.woff. So obviously is not finding the font file.

How can I solve this? Thanks in advance!

@guidoferreyra Could you please provide more information? Where and how are you loading this file? From a page? The assets folder? In a template?

sorry. Yes, both, the css and the fonts, are in the same page folder. So the css has relative path to the fonts. I want to store the font files in the page instead the assets folder, because they change from page to page.

And I’m loading the css folder like this in the header snippet.

  <?php foreach ($page->files()->filterBy('template', 'cssfile') as $cssFile): ?>  
    <?= css( $cssFile->url() )?>
  <?php endforeach ?>

One option would be to create the URL manually:

``

<?php foreach ($page->files() as $cssFile): ?>
<?= css('content/'. $page->id() .'/'. $cssFile->filename() )?>
<?php endforeach ?>

The other option would be to create a [`File::url` component](https://getkirby.com/docs/reference/plugins/components/file-urls).

Note that if you provide files through the content folder, that your content folder has to be in the web root.

thanks! you are the best!

1 Like