From b773a469eb79ed23e3834a1d652f55aefd56ea86 Mon Sep 17 00:00:00 2001 From: azaozz Date: Mon, 25 May 2009 10:39:21 +0000 Subject: [PATCH] Improve Filesystem method choice for 'direct'; introduce FS_METHOD constant, props DD32, fixes #9936 git-svn-id: http://svn.automattic.com/wordpress/trunk@11454 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/file.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 0b7d2289e..2431e2f2c 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -626,18 +626,21 @@ function WP_Filesystem( $args = false ) { * @return unknown */ function get_filesystem_method($args = array()) { - $method = false; - if( function_exists('getmyuid') && function_exists('fileowner') ){ - $temp_file = wp_tempnam(); - if ( getmyuid() == fileowner($temp_file) ) - $method = 'direct'; - unlink($temp_file); - } + $method = defined('FS_METHOD') ? FS_METHOD : false; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets' + + if( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){ + $temp_file_name = ABSPATH . '.' . time(); + $temp_handle = @fopen($temp_file_name, 'w'); + if ( $temp_handle && getmyuid() == fileowner($temp_file_name) ) + $method = 'direct'; + @fclose($temp_handle); + unlink($temp_file_name); + } if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && extension_loaded('sockets') ) $method = 'ssh2'; if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext'; if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread - return apply_filters('filesystem_method', $method); + return apply_filters('filesystem_method', $method, $args); } /**