Make WordPress Core

Ticket #10205: file.php.15646.diff

File file.php.15646.diff, 1.2 KB (added by joelhardi, 14 years ago)
  • wp-admin/includes/file.php

     
    832832function get_filesystem_method($args = array(), $context = false) {
    833833        $method = defined('FS_METHOD') ? FS_METHOD : false; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'
    834834
    835         if ( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
     835        if ( ! $method && ( function_exists('posix_getuid') || function_exists('getmyuid') ) && function_exists('fileowner') ){
    836836                if ( !$context )
    837837                        $context = WP_CONTENT_DIR;
    838838                $context = trailingslashit($context);
    839839                $temp_file_name = $context . 'temp-write-test-' . time();
    840840                $temp_handle = @fopen($temp_file_name, 'w');
    841841                if ( $temp_handle ) {
    842                         if ( getmyuid() == @fileowner($temp_file_name) )
     842                        if ( function_exists('posix_getuid') )
     843                                $uid = posix_getuid(); // *correct* UID of user running script, i.e www's UID
     844                        else
     845                                $uid = getmyuid(); // next-best, UID of user owning script, i.e. johndoe's UID
     846                        if ( $uid == @fileowner($temp_file_name) )
    843847                                $method = 'direct';
    844848                        @fclose($temp_handle);
    845849                        @unlink($temp_file_name);