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!