問題描述

「在這裡插入搜尋引擎」 對於這一點來說是相當無用的 – 我已經看過 wp-includes/functions.phpwp-admin/includes/file.php 等,但沒有找到我所獲得的行為的原因。

我正在執行多站點,當我上傳.doc 或.pdf 時,我沒有問題。當我上傳一個.ppt – 不管實際的檔名或 mimetype(即一個.ppt 重新命名為.txt,一個.txt 重新命名為.ppt) – 我被告知 「對不起,此檔案型別是不允許為安全原因」 還有一點其他的解釋。

我需要修改 mimes 表,新增一個覆蓋 (如果是這樣,這是什麼語法),還是在我的 Apache conf 中?我已經做了一些有趣的搞笑,嘗試在幾個地方鎖定東西,可能阻止.pot 檔案。

最佳解決方案

在多站點網路管理設定中挖掘時發現它:有一個名為 「上傳檔案型別」 的設定 (在資料庫中是 meta_key = wp_sitemeta 表中的”upload_filetypes”),其中包含允許的檔案型別列表。將”ppt” 新增到列表中可以上傳。

次佳解決方案

WordPress 似乎沒有任何地方可以更改這些設定,而不是透過在資料庫中執行此操作。但是你試過使用這個程式碼嗎?

<?php
add_filter('upload_mimes', 'custom_upload_mimes');
function custom_upload_mimes ( $existing_mimes = array() ) {
    // add your extension to the array
    $existing_mimes['ppt'] = 'application/vnd.ms-powerpoint';
    // or: $existing_mimes['ppt|pot|pps'] = 'application/vnd.ms-powerpoint';
    // to add multiple extensions for the same mime type
    // add as many as you like
    // removing existing file types
    unset( $existing_mimes['exe'] );
    // add as many as you like
    // and return the new full result
    return $existing_mimes;
}
?>

在您的主題功能檔案中使用該程式碼。過濾器 upload_mimes 顯然允許您設定其他允許的上傳擴充套件,並且還可以正確設定副檔名 mime 型別以用於 WP 。加上這樣做的好處是它的升級安全。

如果您需要一個 mime 型別的列表:http://www.w3schools.com/media/media_mimeref.asp

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。