WordPress.org

Make WordPress Core

Changeset 7840


Ignore:
Timestamp:
04/25/2008 09:34:54 PM (10 years ago)
Author:
ryan
Message:

tempnam workarounds from DD32. see #6465

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/file.php

    r7644 r7840  
    5555
    5656    return '/tmp/';
     57}
     58
     59function wp_tempnam($filename = '', $dir = ''){
     60    if ( empty($dir) )
     61        $dir = get_temp_dir();
     62    $filename = basename($filename);
     63    if ( empty($filename) )
     64        $filename = time();
     65
     66    $filename = $dir . wp_unique_filename($dir, $filename);
     67    touch($filename);
     68    return $filename;
    5769}
    5870
     
    201213        return new WP_Error('http_no_url', __('Invalid URL Provided'));
    202214
    203     $tmpfname = tempnam(get_temp_dir(), 'wpupdate');
     215    $tmpfname = wp_tempnam($url);
    204216    if( ! $tmpfname )
    205217        return new WP_Error('http_no_file', __('Could not create Temporary file'));
     
    298310}
    299311
    300 function WP_Filesystem( $args = false, $preference = false ) {
     312function WP_Filesystem( $args = false ) {
    301313    global $wp_filesystem;
    302314
    303     $method = get_filesystem_method($preference);
     315    $method = get_filesystem_method();
    304316    if ( ! $method )
    305317        return false;
     
    320332
    321333function get_filesystem_method() {
    322     $tempFile = tempnam(get_temp_dir(), 'WPU');
    323 
    324     if ( getmyuid() == fileowner($tempFile) ) {
    325         unlink($tempFile);
    326         return 'direct';
    327     } else {
    328         unlink($tempFile);
    329     }
    330 
    331     if ( extension_loaded('ftp') ) return 'ftpext';
    332     if ( extension_loaded('sockets') || function_exists('fsockopen') ) return 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
    333     return false;
     334    $method = false;
     335    if( function_exists('getmyuid') && function_exists('fileowner') ){
     336        $temp_file = wp_tempnam();
     337        if ( getmyuid() == fileowner($temp_file) )
     338            $method = 'direct';
     339        unlink($temp_file);
     340    }
     341
     342    if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext';
     343    if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
     344    return apply_filters('filesystem_method', $method);
    334345}
    335346
Note: See TracChangeset for help on using the changeset viewer.