WordPress.org

Make WordPress Core

Ticket #2682: remove_upload_abspath.patch

File remove_upload_abspath.patch, 4.6 KB (added by ryanscheuermann, 8 years ago)

references uploads with ABSPATH and stores relative path in db

  • wp-admin/admin-functions.php

     
    18611861 
    18621862        // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied. 
    18631863        if ( isset($unique_filename_callback) && function_exists($unique_filename_callback) ) { 
    1864                 $filename = $unique_filename_callback($uploads['path'], $file['name']); 
     1864                $filename = $unique_filename_callback(ABSPATH . $uploads['path'], $file['name']); 
    18651865        } else { 
    18661866                $number = ''; 
    18671867                $filename = str_replace('#', '_', $file['name']); 
     
    18801880 
    18811881        // Move the file to the uploads dir 
    18821882        $new_file = $uploads['path'] . "/$filename"; 
    1883         if ( false === @ move_uploaded_file($file['tmp_name'], $new_file) ) 
     1883        if ( false === @ move_uploaded_file($file['tmp_name'], ABSPATH . $new_file) ) 
    18841884                die(printf(__('The uploaded file could not be moved to %s.'), $file['path'])); 
    18851885 
    18861886        // Set correct file permissions 
    1887         $stat = stat(dirname($new_file)); 
     1887        $stat = stat(dirname(ABSPATH . $new_file)); 
    18881888        $perms = $stat['mode'] & 0000666; 
    1889         @ chmod($new_file, $perms); 
     1889        @ chmod(ABSPATH . $new_file, $perms); 
    18901890 
    18911891        // Compute the URL 
    18921892        $url = $uploads['url'] . "/$filename"; 
  • wp-admin/inline-uploading.php

     
    7373 
    7474if ( preg_match('!^image/!', $attachment['post_mime_type']) ) { 
    7575        // Generate the attachment's postmeta. 
    76         $imagesize = getimagesize($file); 
     76        $imagesize = getimagesize(ABSPATH . $file); 
    7777        $imagedata['width'] = $imagesize['0']; 
    7878        $imagedata['height'] = $imagesize['1']; 
    7979        list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']); 
     
    8484 
    8585        if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) { 
    8686                if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 ) 
    87                         $thumb = wp_create_thumbnail($file, 128); 
     87                        $thumb = wp_create_thumbnail(ABSPATH . $file, 128); 
    8888                elseif ( $imagedata['height'] > 96 ) 
    89                         $thumb = wp_create_thumbnail($file, 96); 
     89                        $thumb = wp_create_thumbnail(ABSPATH . $file, 96); 
    9090 
    9191                if ( @file_exists($thumb) ) { 
    9292                        $newdata = $imagedata; 
  • wp-includes/functions-post.php

     
    921921// Returns an array containing the current upload directory's path and url, or an error message. 
    922922function wp_upload_dir() { 
    923923        $siteurl = get_settings('siteurl'); 
    924         //prepend ABSPATH to $dir and $siteurl to $url if they're not already there 
     924        //remove ABSPATH from upload_path if present 
    925925        $path = str_replace(ABSPATH, '', trim(get_settings('upload_path'))); 
    926         $dir = ABSPATH . $path; 
     926        if($path == '') 
     927                $path = 'wp-content/uploads'; 
     928        $dir = $path; 
    927929        $url = trailingslashit($siteurl) . $path; 
    928930 
    929         if ( $dir == ABSPATH ) { //the option was empty 
    930                 $dir = ABSPATH . 'wp-content/uploads'; 
    931         } 
    932  
    933931        if ( defined('UPLOADS') ) { 
    934                 $dir = ABSPATH . UPLOADS; 
     932                $dir = UPLOADS; 
    935933                $url = trailingslashit($siteurl) . UPLOADS; 
    936934        } 
    937935 
     
    945943        } 
    946944 
    947945        // Make sure we have an uploads dir 
    948         if ( ! wp_mkdir_p( $dir ) ) { 
    949                 $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $dir); 
     946        if ( ! wp_mkdir_p( ABSPATH . $dir ) ) { 
     947                $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), ABSPATH . $dir); 
    950948                return array('error' => $message); 
    951949        } 
    952950 
    953     $uploads = array('path' => $dir, 'url' => $url, 'error' => false); 
     951  $uploads = array('path' => $dir, 'url' => $url, 'error' => false); 
    954952        return apply_filters('upload_dir', $uploads); 
    955953} 
    956954 
     
    971969                $ext = ''; 
    972970        else 
    973971                $ext = ".$ext"; 
    974         while ( file_exists($upload['path'] . "/$filename") ) { 
     972        while ( file_exists(ABSPATH . $upload['path'] . "/$filename") ) { 
    975973                if ( '' == "$number$ext" ) 
    976974                        $filename = $filename . ++$number . $ext; 
    977975                else 
     
    979977        } 
    980978 
    981979        $new_file = $upload['path'] . "/$filename"; 
    982         if ( ! wp_mkdir_p( dirname($new_file) ) ) { 
     980        if ( ! wp_mkdir_p( dirname(ABSPATH . $new_file) ) ) { 
    983981                $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file)); 
    984982                return array('error' => $message); 
    985983        } 
    986984 
    987         $ifp = @ fopen($new_file, 'wb'); 
     985        $ifp = @ fopen(ABSPATH . $new_file, 'wb'); 
    988986        if ( ! $ifp ) 
    989987                return array('error' => "Could not write file $new_file."); 
    990988