Cant upload pdf file

Hi!
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


fields:
  about: 
    label: about text
    type: textarea
  phone:
    label: phone number
    type: text
  instagram:
    label: link to instagram
    type: url
  cv:
    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:

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

Dear texnixe,
i’d the very same problem & solution:

Upload with blueprints/files/default.yml:
kirby-upload-issue
When deleting the default.yml, it worked.

I pasted the default.yml:

# default definition of files

title: Default File

accept:
  extension: jpg, jpeg, png, mp3, mp4, ics, mov, pdf, zip, svg, webp
  mime: image/jpg, image/jpeg, image/png, image/gif, image/svg+xml, image/webp, video/mp4

columns:
  - width: 1/2
    fields:
      title:
        label: Titel
        type: text
      alt:
        label: Alternativer Text
        type: text
  - width: 1/2
    fields:
      caption:
        label:
          de: Bildunterschrift
          en: Caption
        type: textarea

Anything wrong with it?

Thx, Thomas

I think the problem is that you don’t have application/pdf in mime types. I wonder if it makes sense to use both extensions and mime type, but if you do, you probably need to add everything to both props. I tested those settings, and I also cannot upload pdf like this. If I remove the second line, it works, and also when adding application/pdf under mime.

1 Like