From 2a8733a159df24441b360451937b5ae0b8b40904 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 25 Apr 2008 21:34:54 +0000 Subject: [PATCH] tempnam workarounds from DD32. see #6465 git-svn-id: http://svn.automattic.com/wordpress/trunk@7840 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/file.php | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 575a6782a4..a7c8228a03 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -56,6 +56,18 @@ function get_temp_dir() { return '/tmp/'; } +function wp_tempnam($filename = '', $dir = ''){ + if ( empty($dir) ) + $dir = get_temp_dir(); + $filename = basename($filename); + if ( empty($filename) ) + $filename = time(); + + $filename = $dir . wp_unique_filename($dir, $filename); + touch($filename); + return $filename; +} + function validate_file( $file, $allowed_files = '' ) { if ( false !== strpos( $file, '..' )) return 1; @@ -200,7 +212,7 @@ function download_url( $url ) { if( ! $url ) return new WP_Error('http_no_url', __('Invalid URL Provided')); - $tmpfname = tempnam(get_temp_dir(), 'wpupdate'); + $tmpfname = wp_tempnam($url); if( ! $tmpfname ) return new WP_Error('http_no_file', __('Could not create Temporary file')); @@ -297,10 +309,10 @@ function copy_dir($from, $to) { return true; } -function WP_Filesystem( $args = false, $preference = false ) { +function WP_Filesystem( $args = false ) { global $wp_filesystem; - $method = get_filesystem_method($preference); + $method = get_filesystem_method(); if ( ! $method ) return false; @@ -319,18 +331,17 @@ function WP_Filesystem( $args = false, $preference = false ) { } function get_filesystem_method() { - $tempFile = tempnam(get_temp_dir(), 'WPU'); - - if ( getmyuid() == fileowner($tempFile) ) { - unlink($tempFile); - return 'direct'; - } else { - unlink($tempFile); + $method = false; + if( function_exists('getmyuid') && function_exists('fileowner') ){ + $temp_file = wp_tempnam(); + if ( getmyuid() == fileowner($temp_file) ) + $method = 'direct'; + unlink($temp_file); } - if ( extension_loaded('ftp') ) return 'ftpext'; - if ( extension_loaded('sockets') || function_exists('fsockopen') ) return 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread - return false; + 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); } ?>