Skip to content

Kirby 3.9.8

File types

Kirby categorizes file types by extension and MIME type. We support a wide range of file types, but of course we cannot predefine them all. You can add your own file types to the system.

Registering a new file type

New file types can be defined in plugins. The array key represents the file extension. Define the matching MIME type and file type category like this:

Kirby::plugin('your/plugin', [
  'fileTypes' => [
    'm4p' => [
      'mime' => 'video/m4p',
      'type' => 'video',
    ],
  ]
]);

Kirby will now recognize m4p files by filename and by MIME type. $file->type() will now return video for such files and they will also be included in the $page->videos() collection. Of course you can now also find them by using $page->files()->filterBy('type', 'video').

type can be audio, code, document, image and video (see Kirby file types). For the mime attribute, you can explore a list of common MIME types.

Image processing

If you want to make your new file type available for image processing, you can set the resizable attribute. It still depends on the thumb driver or your image processing API if it can handle the file type though, but Kirby will now give it a try.

Kirby::plugin('your/plugin', [
  'fileTypes' => [
    'heif' => [
      'mime'      => ['image/heic', 'image/heif'],
      'type'      => 'image',
      'resizable' => true,
    ]
  ]
]);

Image previews

If your new file type should get a preview in the Panel file view, you can set the viewable option. It depends on the browser if it can actually display the file inline.

Kirby::plugin('your/plugin', [
  'fileTypes' => [
    'heif' => [
      'mime'      => ['image/heic', 'image/heif'],
      'type'      => 'image',
      'resizable' => true,
      'viewable'  => true
    ]
  ]
]);