Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_upload_dir [ WordPress Function ]

wp_upload_dir ( $time = null )
Parameters:
  • (string) $time Optional. Time formatted in 'yyyy/mm'.
Uses:
Returns:
  • (array) See above for description.
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 ( 
!== strpos($dirABSPATH) ) {
            
// $dir is absolute, $upload_path is (maybe) relative to ABSPATH
            
$dir path_joinABSPATH$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_replaceUPLOADS'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$time0);
        
$m substr$time5);
        
$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ý

Dahasý ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics