I imagine that this would be a breeze for some - but I'm having difficulty getting just the upload's directory name - not the full path - I've gotten this far:

$uploads = wp_upload_dir();
$upload_path = $uploads['baseurl']; // now how to get just the directory name?

anyone have any ideas? thanks for sharing your experience. . .

  • 5
    basename($uploads['baseurl']) ? Apr 4 '12 at 13:36

This is what you get back from the function:

    [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.


For multisites, you would get something like this:

    [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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.