在WordPress网站上上传.exe文件

6

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


无论您试图通过允许EXE上传来解决什么问题,都很可能有更安全/更好的方法来解决。 - user1751825
尝试这个答案:http://wordpress.stackexchange.com/a/75127/106350 - Ranuka
1
@user1751825 假设我想编写一个程序,从我的WP网站下载安装程序。 - Emil Mocan
@EmilMocan 我的使用情况完全一样 - 比设置单独的服务器容易得多 - 可执行文件下载是网络上常见的做法。 - user2682863
我实际上想添加代码格式,但尝试编辑时告诉我“标题不能包含“在WordPress网站中上传.exe文件”。请提供一个总结您问题的标题。如需帮助,请参见:如何提出好问题? - 这也是我建议的。 - Cadoiz
2个回答

11
感谢您的评论,下面的代码解决了我的问题。
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');

将此添加到我的functions.php中,在WordPress 5.2上运行良好。 - user2682863

4

我遇到了相同的问题,当前答案 对我已经不再适用。

以下内容在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);

我尝试了这个,但在async-upload.php中控制台显示403响应。可能是什么原因? - Game Unity
你尝试过使用基本的文件上传器(旧版)吗?WordPress有两个上传文件的接口。到目前为止,我还没有尝试让它适用于更现代的上传器。 - JoWie
你是指在 /wp-admin/media-new.php 页面吗? - Game Unity
我的服务器上传限制只有64 MB。 - Game Unity

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接