可以在WordPress中上传压缩文件吗?

时间:2012-07-06 作者:Andrew Welch

是否可以允许在Wordpress中上载zip文件?

我有以下代码,但它不工作。

function custom_upload_mimes($existing_mimes = array()) {

// Add *.EPS files to Media upload
    $existing_mimes[\'eps\'] = \'application/postscript\';
// Add *.AI files to Media upload
    $existing_mimes[\'ai\'] = \'application/postscript\';
// Add *.AI files to Media upload
    $existing_mimes[\'3ds\'] = \'application/postscript\';
// Add *.dwg files to Media upload
    $existing_mimes[\'dwg\'] = \'application/acad\';
// Add *.dwg files to Media upload
    $existing_mimes[\'dwg\'] = \'application/x-acad\';
// Add *.dwg files to Media upload
    $existing_mimes[\'dwg\'] = \'application/autocad_dwg\';
// Add *.dwg files to Media upload
    $existing_mimes[\'dwg\'] = \'application/dwg\';
// Add *.dwg files to Media upload
    $existing_mimes[\'dwg\'] = \'application/x-dwg\';
// Add *.dwg files to Media upload
    $existing_mimes[\'dwg\'] = \'application/x-autocad\';
// Add *.dwg files to Media upload
    $existing_mimes[\'dwg\'] = \'drawing/dwg\';
//add .zip
    $existing_mimes[\'zip\'] = \'application/zip\';

    return $existing_mimes;
}

add_filter(\'upload_mimes\', \'custom_upload_mimes\');

3 个回复
最合适的回答,由SO网友:Pontus Abrahamsson 整理而成

以下是在我的网站上有效的操作:

add_filter(\'upload_mimes\', \'custom_upload_mimes\');
function custom_upload_mimes ( $existing_mimes=array() ) {
    // add your extension to the mimes array as below
    $existing_mimes[\'zip\'] = \'application/zip\';
    $existing_mimes[\'gz\'] = \'application/x-gzip\';
    return $existing_mimes;
}

SO网友:Ronny Lindner

如果您使用的是WP MultiSite,则可以通过以下方式配置行为(在WP 3.8.1中测试):

转到浏览器中的网络设置:http://example.com/wp-admin/network/settings.phpzip 对它

SO网友:Ralf

在5.0.3(可能已经更早)中:对于多站点(至少),您可以编辑允许的扩展并在网络设置中添加zip。不再需要编辑文件。

我的网站>网络管理>设置>上载文件类型

结束

相关推荐

404从wp-Content/Uploads/获取图像时

我在获取图像时获得404状态,http仍然包含该图像。图像显示在浏览器中,但404代码中断了一些应用程序。对wp内容/上载/的调用被重定向到。htaccess:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\\.php$ - [L] RewriteRule (.*) /index.php?getfile=$1 [L] </IfModule>&