Ticket #5953: absolute-upload-dir-r6957.patch
File absolute-upload-dir-r6957.patch, 2.5 KB (added by , 17 years ago) |
---|
-
wordpress/wp-includes/functions.php
1022 1022 return false; 1023 1023 } 1024 1024 1025 // Test if a give filesystem path is absolute ('/foo/bar', 'c:\windows') 1026 function 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; 1025 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') 1043 function path_join( $base, $path ) { 1044 if ( path_is_absolute($path) ) 1045 return $path; 1046 1047 return rtrim($base, '/') . '/' . ltrim($path, '/'); 1048 } 1049 1026 1050 // Returns an array containing the current upload directory's path and url, or an error message. 1027 1051 function wp_upload_dir( $time = NULL ) { 1028 1052 $siteurl = get_option( 'siteurl' ); 1029 1053 $upload_path = $dir = get_option( 'upload_path' ); 1030 1054 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 ) ); 1036 1058 1037 1059 if ( !$url = get_option( 'upload_url_path' ) ) 1038 1060 $url = trailingslashit( $siteurl ) . $path; … … 1045 1067 $url = trailingslashit( $siteurl ) . UPLOADS; 1046 1068 } 1047 1069 1070 $subdir = ''; 1048 1071 if ( get_option( 'uploads_use_yearmonth_folders' ) ) { 1049 1072 // Generate the yearly and monthly dirs 1050 1073 if ( !$time ) 1051 1074 $time = current_time( 'mysql' ); 1052 1075 $y = substr( $time, 0, 4 ); 1053 1076 $m = substr( $time, 5, 2 ); 1054 $dir = $dir . "/$y/$m"; 1055 $url = $url . "/$y/$m"; 1077 $subdir = "/$y/$m"; 1056 1078 } 1079 1080 $dir .= $subdir; 1081 $url .= $subdir; 1057 1082 1058 1083 // Make sure we have an uploads dir 1059 1084 if ( ! wp_mkdir_p( $dir ) ) { … … 1061 1086 return array( 'error' => $message ); 1062 1087 } 1063 1088 1064 $uploads = array( 'path' => $dir, 'url' => $url, 'error' => false );1089 $uploads = array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'error' => false ); 1065 1090 return apply_filters( 'upload_dir', $uploads ); 1066 1091 } 1067 1092