Cant upload pdf file

I try to upload a pdf file through the panel and to let it be available for download in the website.
I upload the file regularly and let it be downloadable with a tag href. but when I download the file it says that the file does not exist.

this is the yml:

Title: info

    label: about text
    type: textarea
    label: phone number
    type: text
    label: link to instagram
    type: url
    label: cv PDF file
    type: files

and this is the html:

<a href="<?= $page->cv() ?>" download>Download PDF</a>

When I try to download - it downloads nothing:
Screen Shot 2022-04-19 at 12.07.33 PM

You need to convert the file name (a string saved in the content field) into a file object first, then echo its URL:

<a href="<?= $page->cv()->toFile()->url() ?>" download>Download PDF</a>

you’re right, thanks!
It works now :slight_smile:

I think you should

  1. make sure that only pdf files can be uploaded to that field via assigning a file blueprint: Files | Kirby CMS
  2. make sure you have a file object before you call the url()method
    <?php if ($file =  $page->cv()->toFile()): ?>
      <a href="<?= $file->url() ?>" download>Download PDF</a>
    <?php endif; ?>
1 Like