wp_upload_dir how to get just the directory name .

This is what you get back from the function:

Array
(
    [path] => C:\development\xampp\htdocs\example.com/content/uploads/2012/04
    [url] => http://example.com/content/uploads/2012/04
    [subdir] => /2012/04
    [basedir] => C:\~\example.com/content/uploads
    [baseurl] => http://example.com/content/uploads
    [error] => 
)

So you can get the (as @OneTrickPony pointed out), folder/directory name with

echo wp_basename( $uploads['baseurl'] );

If you’re running multisite and you defined the constant UPLOADS, then you access it from UPLOADS or BLOGUPLOADDIR.

EDIT

For multisites, you would get something like this:

Array
(
    [path] => /var/www/example.com/public_html/wp-content/uploads/sites/2/2016/12,
    [url] => http://example.com/wp-content/uploads/sites/2/2016/12,
    [subdir] => /2016/12,
    [basedir] => /var/www/example.com/public_html/wp-content/uploads/sites/2,
    [baseurl] => http://example.com/wp-content/uploads/sites/2,
    [error] => ,
)

Where the “2” after sites is the blog’s ID

Leave a Comment