Trouble Uploading Custom Font Files via Panel - Need Assistance

Hello Kirby Community,

I’m encountering issues when trying to upload custom font files (OTF, TTF, WOFF, WOFF2) via the Kirby Panel. Despite adjusting the blueprint and server configurations, I receive an “Invalid file type” error. Below I’ve detailed the steps taken and the configurations set.

Blueprint Configuration:

I’ve set up my blueprint with the following configuration to accept font files:

title: Fonts
accept:
  mime:
    - font/ttf
    - font/otf
    - application/font-woff
    - application/font-woff2
  extension:
    - ttf
    - otf
    - woff
    - woff2

My file field looks like this:

HeadingsfontFile:
  type: files
  label: Choose yourt Headings font
  accept:
    mime:
      - font/ttf
      - font/otf
      - font/woff
      - font/woff2
    extension:
      - ttf
      - otf
      - woff
      - woff2

.htaccess Configuration:

I’ve added the necessary MIME types in my .htaccess file:

AddType font/ttf .ttf
AddType font/otf .otf
AddType application/font-woff .woff
AddType application/font-woff2 .woff2

Config.php:

'file' => [
    'mimeTypes' => [
        'ttf' => 'font/ttf',
        'otf' => 'font/otf',
        'woff' => 'application/font-woff',
        'woff2' => 'application/font-woff2'
    ]
]

Custom Plugin - Fonts Uploader:

To address the upload issue, I created a ‘fonts-uploader’ plugin, hoping to circumvent any restrictions and enable the upload of these font files.

<?php

Kirby::plugin('yourname/fonts-uploader', [
    'fileMethods' => [
        'isFont' => function () {
            return in_array($this->extension(), ['otf', 'ttf', 'woff', 'woff2']);
        }
    ],
    'hooks' => [
        'file.create:after' => function ($file) {
            if ($file->isFont()) {
                // zde můžete přidat kód, pokud potřebujete po nahrání souboru písma provést nějakou akci
            }
        }
    ],
    'fileBlueprints' => [
        'fonts' => [
            'title' => 'Font',
            'accept' => [
                'mime' => 'font/otf, font/ttf, font/woff, font/woff2',
                'extension' => ['otf', 'ttf', 'woff', 'woff2'],
                'maxsize' => 2000000 // maximální velikost souboru 2 MB
            ]
        ]
    ]
]);

Result:

The Panel still shows an “Invalid file type” error when attempting to upload any of the specified font file types.

Is there a known issue or a setting I might be missing? I would appreciate any guidance or suggestions from the community, especially if anyone has successfully implemented a similar feature or can identify any errors in my approach.

Thank you for your assistance!

Hi @Jiri_Chlebus, I had a similar issue with uploading lottie animations and you probably have to register the file types like I did:

<?php
// config.php

use Kirby\Filesystem\F;
use Kirby\Filesystem\Mime;

return [
	'hooks' => [
		'system.loadPlugins:after' => function () {
			// support for lottie files
			Mime::$types['lottie'] = 'application/zip';
			F::$types['video'][] = 'lottie';
		},
	],
];

Hope this helps. :slight_smile:

Hi @fabianmichael, thank you, I tried this:

use Kirby\Filesystem\F;
use Kirby\Filesystem\Mime;

return [
    'hooks' => [
        'system.loadPlugins:after' => function () {
            Mime::$types['ttf'] = 'font/ttf';
            Mime::$types['otf'] = 'font/otf';
            Mime::$types['woff'] = 'font/woff';
            Mime::$types['woff2'] = 'font/woff2';
        },
    ],
];

But fonts are still not able to upload.

I guess Kirby also need to recognize the type of a file, have you tried to add them as e.g. document to the Kirby\Filesystem\F::$types array?

use Kirby\Filesystem\F;
use Kirby\Filesystem\Mime;

return [
    'hooks' => [
        'system.loadPlugins:after' => function () {
            Mime::$types['ttf'] = 'font/ttf';
            Mime::$types['otf'] = 'font/otf';
            Mime::$types['woff'] = 'font/woff';
            Mime::$types['woff2'] = 'font/woff2';
            F::$types['document'][] = 'ttf';
            F::$types['document'][] = 'otf';
            F::$types['document'][] = 'woff';
            F::$types['document'][] = 'woff2';
        },
    ],
];

Hi @fabianmichael – it works! Thank you!