My journey with the Symfony MIME type guesser

Smaine Milianni
5 min readJul 3, 2022


Symfony provides a lot of helpful components, among those components, there is the MIME Component.

The Mime component allows manipulating the MIME messages used to send emails and provides utilities related to MIME types.

and provides utilities related to MIME type

Ok, but what is a MIME type ❓

📖 A MIME type is like a standard to classify files so computers know how to handle files, a file with a MIME type application/pdf will be opened by your computer in a PDF reader, file with a MIME type text/html will be opened in a navigator, a file with a MIME type image/jpeg will be opened as an image…

💡The MIME type has 2 parts separated by a “/”. The type and the subtype.

I can hear you: 🗣️ “thanks dude but why should I know this stuff as a developer”

Me: 🗣 ️“When you want to validate a file, you use the MIME type to assert that the file corresponds to what you want, an image for an avatar, a pdf for an invoice, and so on...”

Whatever the kind of file you expect, you should validate it otherwise you’ll have a surprise 💥 .

To do this you have probably already used the File constraint

// src/Entity/Author.php
namespace App\Entity;



Smaine Milianni

Fullstack Developer- certified Symfony 4,5 and certified AWS Solution Architect - Freelancer - Remote Worker