WordPress.org

Make WordPress Core

Changeset 6984


Ignore:
Timestamp:
02/22/08 17:46:03 (8 years ago)
Author:
ryan
Message:

Upload path fixes from tellyworth. see #5953

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r6983 r6984  
    10231023} 
    10241024 
     1025// Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows') 
     1026function path_is_absolute( $path ) { 
     1027    // this is definitive if true but fails if $path does not exist or contains a symbolic link 
     1028    if ( realpath($path) == $path ) 
     1029        return true; 
     1030 
     1031    if ( strlen($path) == 0 || $path{0} == '.' ) 
     1032        return false; 
     1033     
     1034    // windows allows absolute paths like this 
     1035    if ( preg_match('#^[a-zA-Z]:\\\\#', $path) ) 
     1036        return true; 
     1037 
     1038    // a path starting with / or \ is absolute; anything else is relative 
     1039    return (bool) preg_match('#^[/\\\\]#', $path); 
     1040} 
     1041 
     1042// Join two filesystem paths together (e.g. 'give me $path relative to $base') 
     1043function path_join( $base, $path ) { 
     1044    if ( path_is_absolute($path) ) 
     1045        return $path; 
     1046     
     1047    return rtrim($base, '/') . '/' . ltrim($path, '/'); 
     1048} 
    10251049 
    10261050// Returns an array containing the current upload directory's path and url, or an error message. 
     
    10291053    $upload_path = $dir = get_option( 'upload_path' ); 
    10301054     
    1031     if ( $upload_path != realpath( $upload_path ) ) { // not an absolute path 
    1032         //prepend ABSPATH to $dir and $siteurl to $url if they're not already there 
    1033         $path = str_replace( ABSPATH, '', trim( $upload_path ) ); 
    1034         $dir = ABSPATH . $path; 
    1035     } 
     1055    // $dir is absolute, $path is (maybe) relative to ABSPATH 
     1056    $dir = path_join( ABSPATH, $upload_path ); 
     1057    $path = str_replace( ABSPATH, '', trim( $upload_path ) ); 
    10361058 
    10371059    if ( !$url = get_option( 'upload_url_path' ) ) 
     
    10461068    } 
    10471069 
     1070    $subdir = ''; 
    10481071    if ( get_option( 'uploads_use_yearmonth_folders' ) ) { 
    10491072        // Generate the yearly and monthly dirs 
     
    10521075        $y = substr( $time, 0, 4 ); 
    10531076        $m = substr( $time, 5, 2 ); 
    1054         $dir = $dir . "/$y/$m"; 
    1055         $url = $url . "/$y/$m"; 
    1056     } 
     1077        $subdir = "/$y/$m"; 
     1078    } 
     1079     
     1080    $dir .= $subdir; 
     1081    $url .= $subdir; 
    10571082 
    10581083    // Make sure we have an uploads dir 
     
    10621087    } 
    10631088 
    1064         $uploads = array( 'path' => $dir, 'url' => $url, 'error' => false ); 
     1089    $uploads = array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'error' => false ); 
    10651090    return apply_filters( 'upload_dir', $uploads ); 
    10661091} 
Note: See TracChangeset for help on using the changeset viewer.