問題描述

根據 WordPress 的程式碼,FS_METHOD = 'direct'是適當的選擇。

(Primary Preference) “direct” forces it to use Direct File I/O requests from within PHP, this is fraught with opening up security issues on poorly configured hosts, This is chosen automatically when appropriate.

http://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants

適合的標準是什麼?

最佳解決方案

這裡是程式碼 from wp-admin/includes/file.php

if ( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
    if ( !$context )
        $context = WP_CONTENT_DIR;

    // If the directory doesn't exist (wp-content/languages) then use the parent directory
    // as we'll create it.
    if ( WP_LANG_DIR == $context && ! is_dir( $context ) )
        $context = dirname( $context );

    $context = trailingslashit($context);
    $temp_file_name = $context . 'temp-write-test-' . time();
    $temp_handle = @fopen($temp_file_name, 'w');
    if ( $temp_handle ) {
        if ( getmyuid() == @fileowner($temp_file_name) )
            $method = 'direct';
        @fclose($temp_handle);
        @unlink($temp_file_name);
    }
}

測試似乎是

  1. 我們可以在 wp-content 或 wp-content /languages 目錄中建立一個臨時檔案嗎?

  2. 該檔案是否屬於當前的 Unix 使用者,即 wp-content 上沒有 setuid?

如果我們自己沒有指定 FS_METHOD,並且如果必要的檔案系統呼叫檢查#2,則只執行此檢查。臨時檔案隨後被清理。

參考文獻

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