Mime type issue (again)

Even since Kirby 2.1 I have issues with the mime-type detection while replacing media using the panel.

Uploading an avatar (for a user) never worked (says I can only upload valid image files) - and with Kirby 2.2 I could only upload images, after altering the Kirby core myself.

With Kirby 2.3 I’ve run into a new issue, see the screenshots;

The original image is a .jpg file, but when I hit “replace” I can only upload “custom files” (it’s not recognized as a .jpg).

When I try to upload another .jpg file, I get the message “I can only upload images of the same kind”.

  1. It is an image of the same kind :slight_smile:
  2. Why can’t I replace a JPG with a PNG?

Let’s try another image;

It’s a valid .JPG file (created in Photoshop - just like the image before), but this one says I have to replace it with a PNG file… when doing so, off course, I get the message I can not replace a JPG with a PNG.

Any idea? I can upload media (not to the avatar section) but I can never, ever replace it…

Running XAMP (latest), PHP (latest), everything out of the box on a localhost (W10).

I tried WAMP, but that didn’t work as well.

On my deployment / production server (Apache) everything works well… so I guess it’s related to Windows / XAMPP?

BTW. Love Kirby! :slight_smile:

1 Like

Yes, that problem has already been described somewhere else and is Windows related. The way the mime-type is queried is not recognized on Windows. It’s not Xampp specific, though, I got the same result when testing with MAMP on Windows.

I even tried LAMP (Virtual Box) :stuck_out_tongue:

I did solve the issue with these corrections;

Now I can upload / replace the files - even replace JPG with PNG, vice versa - etc…

What can I do to solve this (besides buying a Mac…)?

BTW. The “fileinfo” extension (PHP) is loaded correctly…

1 Like

It does this to me also on Windows MAMP but not while simply running the default php server
php -S localhost:8000
Can you try that?

I’ll give it a try - I’ve tried XAMMP / MAMP / LAMP and WAMP now :slight_smile: - thx!

Maybe it’s an option for the dev’s to change the mime-type detection on Windows systems;

Using Drupal / Joomla / Typo3 / Concrete and Wordpress doesn’t give me troubles - but Kirby rejects the mime-type sniffing, I guess :’(

- edit - Not sure if the “other” CMS’s do MIME-sniffing (at least Wordpress does, but I’m not sure for the others).

I would be nice, when Windows was supported… and please, give the option to replace a .PNG with a .JPG :slight_smile:

Some clients upload 3mb PNG-images, which have the same quality when replaced by 1mb JPG ones…

1 Like

I agree that we should have a solution for this, either in the way mime type detection is done in the core, or at least how to configure the server under Windows to get it right.

1 Like

I don’t know how popular Kirby is, under Windows user (well, it’s quite popular for me :stuck_out_tongue: )…

I have tried http://www.usbwebserver.net/en/ some minutes ago - but that one doesn’t do proper MIME-support as well… to bad for me Windows lover :slight_smile:

1 Like

I think our mime sniffing is pretty robust. Here’s what we do on the backend:

  1. we try via finfo_file extension
  2. we try via mime_content_type
  3. we try via command line
  4. we try via a MimeReader library
  5. we try to convert the extension to the correct mime type

But in this case I think it has something to do with the browser acting up. I had super weird issues with Firefox when it comes to mime types.

In 2.3 I added the mime type to the file upload field, which normally sets the allowed files correctly, but this does not seem to work here unfortunately.

I also think that during the upload the mime type is not correctly submitted via the browser here.

The PNG / JPG issue is something entirely different. It’s intentional that you can only replace files with the same type. It’s a protective feature for clients, so they don’t replace files with the wrong types all the time and links break all over the place. When you have to remove an image first and reupload it afterwards, you have to clearly think if this is the right thing to do. You know what I mean?


Thanks for the answer - we’ve been in touch for the same issue before;

During Kirby 2.2 I was not able to upload images on a regular server; I gave you access to that online server and also submitted some code to solve it (well, I hope it does :slight_smile: ).

It worked back then, but know (using a local machine) I can’t upload / replace images once again.

Please mention; I do not want to be negative at all for Kirby, it’s the best CMS I’ve seen :slight_smile: - but I am looking for a solutions for those pesky Windows - users out there :stuck_out_tongue:

BTW. I am developing using Webkit / Chrome - I’ll try Firefox / Edge right now.

1 Like

Well, things do became strange on my Windows pc / XAMMP / default localhost.

Replacing images

  1. Chrome, doesn’t see proper mime-type, does not allow replace.
  2. Edge, sometimes it works (replace, upload) / sometimes it doesn’t do anything (no error messages, nothing).
  3. Firefox, the same as 1) - Chrome.
  4. Safari (old one…) doesn’t do anything at all (guess it’s deprecated, since Apple stopped support for Windows).

So basically I can upload images in Chrome / Firefox and sometimes replace them… Edge sometimes works, sometimes not (can’t detect any logic).

Guess I’ll stay with my modified script (works in all browsers, besides deprecated Safari).

- edit - Tested on both USB Server (mentioned above) and XAMMP.

1 Like

We’ll have to check more closely what’s going on there. We definitely want it to work on Windows as well. Might need a bit of time though. Such stuff is mostly a pain in the ass to debug :slight_smile:


The results I get are - at best - very unpredictable;

Sometimes I can replace, sometimes not - sometimes it works with an incorrect .extension and the 2nd time I try not…

###I’ve made a workaround, which suites my needs for the moment

Just alter / add these lines;


/* --------------------------------------------------
  Allow media replacement - true | false
-------------------------------------------------- */

c::set('kirbyReplaceMedia', true);


// add those at line-number #9
use C;
DEFINE('MEDIAREPLACE', c::get('kirbyReplaceMedia', false));

// change this at line-number #81 (after adding the first two lines)
  if($upload->mime() != $file->mime() && !MEDIAREPLACE) {
    throw new Error(l('files.replace.error.type'));

That’s it - now you can set your preference for replacing media ánd you can always upload / replace media using a Windows development machine.

PS. Use at own risk :stuck_out_tongue: … and I don’t know Kirby’s code very good - so don’t blame my syntax :slight_smile: