I need to allow .exe file uploads through the admin media manager. So far I have tried
function enable_extended_upload ( $mime_types = array() ) {
$mime_types['exe'] = 'application/octet-stream';
return $mime_types;
}
add_filter('upload_mimes', 'enable_extended_upload');
Three different sources have given me three different mime types for .exe. They are application/octet-stream
, application/exe
, and application/x-msdownload
. None have worked.
Since my site happens to be a network, I’ve tried to whitelist the filetype under Network Settings -> Upload Settings, like so
It didn’t work either.
The only thing that works is setting the constant define('ALLOW_UNFILTERED_UPLOADS', true);
in wp-config.php, AND having the above mime type snippet, but is not the ideal solution since all files will be allowed.
How can I whitelist .exe nowadays?
2 Answers
WordPress provide a hook to change the default mime types, like your hint in the question. The follow small code source demonstrated the change to allow a exe-file.
add_filter( 'upload_mimes', 'fb_enable_extended_upload' );
function fb_enable_extended_upload ( array $mime_types = [] ) {
$mime_types[ 'exe' ] = 'application/exe';
return $mime_types;
}
It is not necessary to change the database entry upload_filetypes
.