Checks uploaded file content roughly matches a known MIME type for the file extension.
Checks uploaded file content roughly matches a known MIME type for the file extension.
It can be used with FileField
or any subclasses like UploadField
.
For example, it will fail validation if someone renames a .exe
file to .jpg
and attempts to upload the file.
Note: For a SilverStripe 3.x compatible version, please use the 1.x release line.
Install with composer by running composer require silverstripe/mimevalidator
in the root of your SilverStripe project.
The validator is not used by default. It can be enabled in a couple of ways:
In your mysite/_config/config.yml
file:
SilverStripe\Core\Injector\Injector:
SilverStripe\Assets\Upload_Validator:
class: SilverStripe\MimeValidator\MimeUploadValidator
$field = UploadField::create();
$field->setValidator(MimeUploadValidator::create());
By default MIME types are checked against HTTP.MimeTypes config set in framework. This can be limiting as this only
allows for one MIME type per extension. To allow for multiple MIME types per extension, you can add these in your YAML
config as below:
SilverStripe\MimeValidator\MimeUploadValidator:
MimeTypes:
ics:
- 'text/plain'
- 'text/calendar'
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem