I wrote validation function that tests file's mimetype. I commented out my old validators to avoid validation by extension:
'DownloadFile' => array( '#type' => 'managed_file', '#title' => t("Download"), '#title_display' => 'invisible', //'#description' => t('Allowed extensions: pdf zip exe.'), '#upload_validators' => array( //'file_validate_extensions' => array('pdf zip exe'), 'file_validate_size' => array(variable_get('mymodule_image_size', 2 * 1024 * 1024)), ), '#upload_location' => 'public://mymodule/download', '#default_value' => $item->DownloadFile, '#required' => TRUE, '#theme' => 'preview_upload', ),
Now when I'm trying to upload exe, I get:
The specified file putty.exe could not be uploaded. Only files with the following extensions are allowed: jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp.
Now, I will have files without extensions there. And with extensions I cannot predict. And all I want sometimes is to test for a proper MIME type match, not even an exact mimetypes sometimes. So, how can I get rid of extension validation and turn it into "everything goes"?
I managed to find issue that seemed to be about this problem, but it tells to
unset($element['#upload_validators']['file_validate_extensions']); - does not make sense to me as I'm creating brand new array and this isn't set at all.
I tried to use
#process property to add a function that will unset default validators later, like shown there in issue, but
dpr($element) shows there is nothing to unset:
[#upload_validators] => Array ( [file_validate_size] => Array (  => 2097152 ) )