wp_upload_dir [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Get an array containing the current upload directory's path and url.
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.
Source
<?php
function wp_upload_dir( $time = null ) {
global $switched;
$siteurl = get_option( 'siteurl' );
$upload_path = get_option( 'upload_path' );
$upload_path = trim($upload_path);
$main_override = is_multisite() && defined( 'MULTISITE' ) && is_main_site();
if ( empty($upload_path) ) {
$dir = WP_CONTENT_DIR . '/uploads';
} else {
$dir = $upload_path;
if ( 'wp-content/uploads' == $upload_path ) {
$dir = WP_CONTENT_DIR . '/uploads';
} elseif ( 0 !== strpos($dir, ABSPATH) ) {
// $dir is absolute, $upload_path is (maybe) relative to ABSPATH
$dir = path_join( ABSPATH, $dir );
}
}
if ( !$url = get_option( 'upload_url_path' ) ) {
if ( empty($upload_path) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) )
$url = WP_CONTENT_URL . '/uploads';
else
$url = trailingslashit( $siteurl ) . $upload_path;
}
if ( defined('UPLOADS') && !$main_override && ( !isset( $switched ) || $switched === false ) ) {
$dir = ABSPATH . UPLOADS;
$url = trailingslashit( $siteurl ) . UPLOADS;
}
if ( is_multisite() && !$main_override && ( !isset( $switched ) || $switched === false ) ) {
if ( defined( 'BLOGUPLOADDIR' ) )
$dir = untrailingslashit(BLOGUPLOADDIR);
$url = str_replace( UPLOADS, 'files', $url );
}
$bdir = $dir;
$burl = $url;
$subdir = '';
if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
// Generate the yearly and monthly dirs
if ( !$time )
$time = current_time( 'mysql' );
$y = substr( $time, 0, 4 );
$m = substr( $time, 5, 2 );
$subdir = "/$y/$m";
}
$dir .= $subdir;
$url .= $subdir;
$uploads = apply_filters( 'upload_dir', array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false ) );
// Make sure we have an uploads dir
if ( ! wp_mkdir_p( $uploads['path'] ) ) {
$message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $uploads['path'] );
return array( 'error' => $message );
}
return $uploads;
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/wp upload dir « WordPress Codex
Description. Returns an array of key => value pairs containing path information on the currently configured uploads directory.
codex.wordpress.org - WordPress › Support » Multisite main site wp_upload_dir
**NOTE: I'm not talking about "URL rewriting" in a server header sense. I'm talking about the relative URL path to the image file when you insert a photo into a ...
wordpress.org - Wp_upload_dir | WP Code Snippets
Mar 5, 2011 ... Among the many facets of designing a web site, one key factor is considering visitor convenience. It should be easy to find content on your site ...
wpcodesnippets.info - wp_upload_dir | Big Things & Little Things
Feb 21, 2012 ... Useful little piece of WordPress code, plays a particularly useful part of a dynamic featured post slideshow that I was going to detail at some ...
www.bigthingsandlittlethings.co.uk
Kullanýcý Tartýþmalarý [ wordpress.org ]
- thinkunique on "Multisite main site wp_upload_dir"
- Andrea_r on "Multisite main site wp_upload_dir"
- Ipstenu on "Multisite main site wp_upload_dir"
- nootron on "Multisite main site wp_upload_dir"
- proque on "[Plugin: User Photo] 2 Warnings with WP 2.5 Permission error & Header error"
- steamfrog on "[Plugin: User Photo] 2 Warnings with WP 2.5 Permission error & Header error"
- susanohnj on "[Plugin: User Photo] 2 Warnings with WP 2.5 Permission error & Header error"
- 12a3.vn on "[Plugin: User Photo] 2 Warnings with WP 2.5 Permission error & Header error"
- mafiamoso on "[Plugin: User Photo] 2 Warnings with WP 2.5 Permission error & Header error"
- 12a3.vn on "[Plugin: User Photo] 2 Warnings with WP 2.5 Permission error & Header error"