在WordPress网站上传.exe文件

时间:2016-12-20 04:51:06

标签: wordpress

我需要在我的wordpress网站上传.exe文件。我已经添加了define(' ALLOW_UNFILTERED_UPLOADS',true);在我的wp-config.php文件中,但仍然显示相同的错误。请帮忙。 感谢

2 个答案:

答案 0 :(得分:5)

感谢您的评论,下面的代码解决了我的问题,

function enable_extended_upload ( $mime_types =array() ) {

   // The MIME types listed here will be allowed in the media library.
   // You can add as many MIME types as you want.
   $mime_types['exe']  = 'application/exe'; 

   return $mime_types;
} 
add_filter('upload_mimes', 'enable_extended_upload');

答案 1 :(得分:0)

我遇到了同样的问题,当前的答案 (https://stackoverflow.com/a/41251700/3948974) 不再适合我。

以下在 wordpress 5.7.2 中对我有用(使用基本文件上传器测试):

在“wp-content/mu-plugins”目录下新建一个.php文件,内容如下:

<?php

// specify a high priority so that the filter will run later
// there is a built in filter which will remove the entry for 'exe'
add_filter('upload_mimes', function($mimes) {
    // this mimetype has to match exactly what 
    // finfo_file() will return, see wp_check_filetype_and_ext()
    $mimes['exe'] = 'application/x-dosexec';
    return $mimes;
}, 10000);