File Settings
File fields
You can store any additional meta data for a file. This can be very handy to add captions to images or provide more information about downloads, etc.
The form, in which this data can be entered can be found in the sidebar of the fileviewer. Additional fields can be setup just like page fields. All field types, which are available for pages are also available for files.
Please check out the cheat sheet for a full list of available Panel field types.
The configuration for those fields go right into the file settings:
…
files:
fields:
caption:
label: Caption
type: textarea
…
File limits
Sometimes you only want specific file type to be uploaded to a certain template. To restrict Panel users to upload other types, you can add a type
field to the file's meta data in the blueprint. Please check out the list of all available file types.
…
files:
type: document
…
To allow multiple types provide a list of the file types you want:
…
files:
type:
- image
- video
…
You can also set the maximum number of files (of any type), which will hide the "Add" button as soon as the maximum is reached.
…
files:
max: 5
…
To limit the file size on a per template basis you have to add a size
field to the file's meta data, specifying the maximum file size in bytes.
…
files:
size: 12000000
…
For images you can also define limits for their width and height by adding the respective width
and/or height
field to the file's meta data. These only apply for images and will be ignored for other file formats.
…
files:
width: 500
height: 300
…
Sortable files
Files are sorted by their filenames by default. Since Kirby 2 it's also possible to sort files by drag & drop in the files manager. You have to switch this feature on in the blueprint's file settings. Sorting files by drag & drop will add a sort
field to the file's meta data. Here's how to activate manual sorting.
…
files:
sortable: true
…
To make use of manual sorting in your templates you must sort files by the newly generated sort field:
<?php foreach($page->files()->sortBy('sort', 'asc') as $file): ?>
…
<?php endforeach ?>
Hide files
Like pages, files can be entirely hidden in the Panel as well. They won't appear in the sidebar and the files manager will not be accessible either. This can be helpful if Panel users shouldn't be able to view or edit files for certain pages.
files:
hide: true
Sanitization
Kirby's file uploader automatically sanitizes filenames to avoid broken links due to special characters in filenames. You can switch this off now in your blueprints with the sanitization option:
files:
sanitize: false