## Description

Returns an array of key => value pairs containing path information on the currently configured uploads directory.

Checks the 'upload_path' option, which should be from the web root folder, and if it isn't empty it will be used. If it is empty, then the path will be 'WP_CONTENT_DIR/uploads'. If the 'UPLOADS' constant is defined, then it will override the 'upload_path' option and 'WP_CONTENT_DIR/uploads' path.

The upload URL path is set either by the 'upload_url_path' option or by using the 'WP_CONTENT_URL' constant and appending '/uploads' to the path.

If the 'uploads_use_yearmonth_folders' is set to true (checkbox if checked in the administration settings panel), then the time will be used. The format will be year first and then month.

If the path couldn't be created, then an error will be returned with the key 'error' containing the error message. The error suggests that the parent directory is not writable by the server.

On success, the returned array will have many indices:

* 'path' - base directory and sub directory or full path to upload directory.
* 'url' - base url and sub directory or absolute URL to upload directory.
* 'subdir' - sub directory if uploads use year/month folders option is on.
* 'basedir' - path without subdir.
* 'baseurl' - URL path without subdir.
* 'error' - set to false.


<?php $upload_dir = wp_upload_dir(); ?>  ## Parameters tt$time/tt
(string) (optional) Time formatted in 'yyyy/mm'.
Default: nullnoinclude

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

## Notes

This template is for standardizing how parameters look in the Function Reference and in Template Tags. Here is an example of this template being called: prenowiki检查到模板循环：模板:Parameter/nowiki/pre 检查到模板循环：模板:Parameter

The usage of this template is below: prenowiki检查到模板循环：模板:Parameter/nowiki/pre Let's take a closer look at the parameters..

name
The name of the parameter.
datatype
The datatype that should be given for this parameter when called.
• string
• integer
• boolean
• mixed
description
A short description of the parameter.
importance
Set this parameter to optional if the parameter is optional. Otherwise, do not declare this parameter—it defaults to required.
• required
• optional
default
If this parameter is optional, ttdefault/tt is the value that will be used if the parameter is not declared.

wordpress.org.cn /div /noinclude

## Example

Basic example to produce the upload directory URL.

<?php $upload_dir = wp_upload_dir(); ?> <?php echo$upload_dir['baseurl']; ?>


More in-depth break down of the data returned.

<?php
$uploads = wp_upload_dir(); // Array of key => value pairs /*$uploads now contains something like the following (if successful)
Array (
[subdir] => /2010/05
[error] =>
)
// Descriptions
[path] - base directory and sub directory or full path to upload directory.
[url] - base url and sub directory or absolute URL to upload directory.
[subdir] - sub directory if uploads use year/month folders option is on.
[basedir] - path without subdir.
[baseurl] - URL path without subdir.
[error] - set to false.
*/

echo $uploads['path'] . '<br />'; echo$uploads['url'] . '<br />';
echo $uploads['subdir'] . '<br />'; echo$uploads['basedir'] . '<br />';
echo $uploads['baseurl'] . '<br />'; echo$uploads['error'] . '<br />';

$upload_dir = ($uploads['url'] );
$upload_dir_alt = ($uploads['baseurl'] . $uploads['subdir'] ); // Now echo the final result echo$upload_dir . '<br />'; // Output - http://example.com/wp-content/uploads/2010/05

// Using year and month based folders, the below will be the same as the line above.

## Folder Name

In case you want to move the /uploads folder, you'll have to use the UPLOADS constant. It normally shouldn't get used, as it only get's defined when ms_default_constants() is run (only multisite), but you can simply set

define( 'UPLOADS', trailingslashit( WP_CONTENT_FOLDERNAME ).'custom_uploads_name' );


in a single site install and it will just work, as the public directory structure function wp_upload_dir() sets it up, when it was defined: $dir = ABSPATH . UPLOADS;. Note: You can extract the folder name with the following line: // returns false if the UPLOADS constant is not defined$upload_dir_name = false;
if ( defined( 'UPLOADS' ) )
str_replace( trailingslashit( WP_CONTENT_FOLDERNAME ), '', untrailingslashit( UPLOADS ) );


Since: 2.0.0

## Source File

div class=template-description style=padding: 0 1.5em; border: 1px solid #eeeeee; background-color: #f9f9f9

## Template Description

Link to the source code on http://core.trac.wordpress.org/browser/.

### Parameters

1. filename
2. (option) path to codetag/code (version) or codetrunk/code. This option is only used for a new function.br /Default: codetrunk/code -- trunk is the latest bleeding edge development version of WordPress.

### Usage

Link to the stable version: pre检查到模板循环：模板:Trac/pre

/div

wordpress.org.cn.

## Description

This Template is used by Codex:Template Messages.

## Usage

pre 检查到模板循环：模板:Message /pre

/noinclude