File Mime Type Checker
Categories
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
Drupal 7 file validation is performed by file_validate_extensions which only relies on the file name extension. By using 'File Mime Type Checker', you can check the mime type of the file. 'File Mime Type Checker' uses the php library 'fileinfo' and is dependent on that. Through this php lib we can perform a more secure and reliable check on the file's mime type and compare that to the allowed file extensions, as these are set by the admin within the content type's field settings.
This module performs a server side validation for the extension of an uploaded file of any content type's file field. User can validate the file field according to the condition (Enable Mime Type Check in file or image field).
Similar projects
MumeDetect
How they are diffrent
1. Admin can use for file or image field on the basis of requirement. If not required then admin can unselect the field for mime type checker in the field configuration.
2. User can use mime type checker for the form api.
Dependencies
The module depends on the php library fileinfo. Please make sure this library is present and enabled on the server.
Installation
Install module like usual. No special installation considerations
Configuration
After enabling this module, please check admin/config/media/mime_type.
Here you can set the default value for check mime type of the fields.
Usage
To enable a form to validate file field or image field, simply set #file_check in the form array to TRUE.
$form['file'] = array(
'#type' => 'managed_file',
'#title' => t('Image'),
'#description' => t('Upload a file, allowed extensions: gif png jpg jpeg'),
'#upload_validators' => array(
'file_validate_extensions' => array('gif png jpg jpeg'),
),
'#file_check' => TRUE
);
