77 * @return string Full filesystem path to the root of the WordPress installation |
79 * @return string Full filesystem path to the root of the WordPress installation |
78 */ |
80 */ |
79 function get_home_path() { |
81 function get_home_path() { |
80 $home = get_option( 'home' ); |
82 $home = get_option( 'home' ); |
81 $siteurl = get_option( 'siteurl' ); |
83 $siteurl = get_option( 'siteurl' ); |
82 if ( $home != '' && $home != $siteurl ) { |
84 if ( ! empty( $home ) && 0 !== strcasecmp( $home, $siteurl ) ) { |
83 $wp_path_rel_to_home = str_replace($home, '', $siteurl); /* $siteurl - $home */ |
85 $wp_path_rel_to_home = str_ireplace( $home, '', $siteurl ); /* $siteurl - $home */ |
84 $pos = strrpos($_SERVER["SCRIPT_FILENAME"], $wp_path_rel_to_home); |
86 $pos = strripos( str_replace( '\\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) ); |
85 $home_path = substr($_SERVER["SCRIPT_FILENAME"], 0, $pos); |
87 $home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos ); |
86 $home_path = trailingslashit( $home_path ); |
88 $home_path = trailingslashit( $home_path ); |
87 } else { |
89 } else { |
88 $home_path = ABSPATH; |
90 $home_path = ABSPATH; |
89 } |
91 } |
90 |
92 |
223 * @uses wp_upload_dir |
225 * @uses wp_upload_dir |
224 * @uses wp_unique_filename |
226 * @uses wp_unique_filename |
225 * @uses delete_transient |
227 * @uses delete_transient |
226 * @param array $file Reference to a single element of $_FILES. Call the function once for each uploaded file. |
228 * @param array $file Reference to a single element of $_FILES. Call the function once for each uploaded file. |
227 * @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). |
229 * @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). |
|
230 * @param string $time Optional. Time formatted in 'yyyy/mm'. |
228 * @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). |
231 * @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). |
229 */ |
232 */ |
230 function wp_handle_upload( &$file, $overrides = false, $time = null ) { |
233 function wp_handle_upload( &$file, $overrides = false, $time = null ) { |
231 // The default error handler. |
234 // The default error handler. |
232 if ( ! function_exists( 'wp_handle_upload_error' ) ) { |
235 if ( ! function_exists( 'wp_handle_upload_error' ) ) { |
355 * @uses current_user_can |
358 * @uses current_user_can |
356 * @uses wp_upload_dir |
359 * @uses wp_upload_dir |
357 * @uses wp_unique_filename |
360 * @uses wp_unique_filename |
358 * @param array $file an array similar to that of a PHP $_FILES POST array |
361 * @param array $file an array similar to that of a PHP $_FILES POST array |
359 * @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). |
362 * @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). |
|
363 * @param string $time Optional. Time formatted in 'yyyy/mm'. |
360 * @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). |
364 * @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). |
361 */ |
365 */ |
362 function wp_handle_sideload( &$file, $overrides = false ) { |
366 function wp_handle_sideload( &$file, $overrides = false, $time = null ) { |
363 // The default error handler. |
367 // The default error handler. |
364 if (! function_exists( 'wp_handle_upload_error' ) ) { |
368 if (! function_exists( 'wp_handle_upload_error' ) ) { |
365 function wp_handle_upload_error( &$file, $message ) { |
369 function wp_handle_upload_error( &$file, $message ) { |
366 return array( 'error'=>$message ); |
370 return array( 'error'=>$message ); |
367 } |
371 } |
434 if ( !$type ) |
438 if ( !$type ) |
435 $type = $file['type']; |
439 $type = $file['type']; |
436 } |
440 } |
437 |
441 |
438 // A writable uploads dir will pass this test. Again, there's no point overriding this one. |
442 // A writable uploads dir will pass this test. Again, there's no point overriding this one. |
439 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) |
443 if ( ! ( ( $uploads = wp_upload_dir( $time ) ) && false === $uploads['error'] ) ) |
440 return $upload_error_handler( $file, $uploads['error'] ); |
444 return $upload_error_handler( $file, $uploads['error'] ); |
441 |
445 |
442 $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); |
446 $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback ); |
443 |
447 |
444 // Strip the query strings. |
448 // Strip the query strings. |