Wp_upload_dir() not reporting correct path

Has anyone had problems using the wp_upload_dir() function. In my install which is on ubuntu it reports as /www/kinsta/public/framerpress/wp-content/uploads/ but is actually /home/robert/DevKinsta/public/framerpress/wp-content/uploads

$uploads = wp_uploads_dir();

So my script is unable to find the files I have in uploads. Is there some other way I should be doing this?

Hello @Robert_Craig :wave: Welcome to DevKinsta community!

I’ve checked the same with this simple PHP script I took from the Internet (and that I modified a bit) - as I’m not a web developer/programmer :smiley: and, I then saved that php file under my /home/myusername/DevKinsta/public/my-site-site/

include( 'wp-load.php' );

$upload_dir = wp_upload_dir(); // Array of key => value pairs
    $upload_dir now contains something like the following (if successful)
    Array (
        [path] => C:\path\to\wordpress\wp-content\uploads\2010\05
        [url] => http://example.com/wp-content/uploads/2010/05
        [subdir] => /2010/05
        [basedir] => C:\path\to\wordpress\wp-content\uploads
        [baseurl] => http://example.com/wp-content/uploads
        [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 "Upload dir: <br /><br />";
echo "Path: " . $upload_dir['path'] . '<br />';
echo "URL: " . $upload_dir['url'] . '<br />';
echo "Subdir: " . $upload_dir['subdir'] . '<br />';
echo "Basedir: " .$upload_dir['basedir'] . '<br />';
echo "Baseurl: " . $upload_dir['baseurl'] . '<br />';
echo $upload_dir['error'] . '<br />';

$upload_url = ( $upload_dir['url'] );
$upload_url_alt = ( $upload_dir['baseurl'] . $upload_dir['subdir'] );

// Now echo the final result
echo "Upload URL: " . $upload_url . '<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.
echo "Upload URL alt: " . $upload_url_alt . '<br />'; // Output - http://example.com/wp-content/uploads/2010/05

and indeed, the “basedir” from that wp_upload_dir() function returned with something like (which is expected):


instead of something like this:


Screenshot from 2022-12-16 10-20-25

It’s because the basedir array value would be returned by the PHP that’s processed in the FPM docker container (the WordPress/site’s php scripts are processed by the PHP inside this FPM docker container) where the particular site’s path is located under that /www/kinsta/public/site-name/

You can enter to that docker fpm container via command line (from the Linux terminal) with this command:

docker exec -it devkinsta_fpm bash

In that docker fpm container, if you run the PHP script via CLI ( php scriptname.php ) , it would return the same basedir value:

Hope this helps/answers to your question and you may want to use that basedir value returned
(e.g: /www/kinsta/public/framerpress/wp-content/uploads/ ) in your custom script to make it work correctly/properly :smiley: . You may also want to consult with your web developers/programmers if necessary, as we don’t provide support for custom PHP scripts/development related.


Hi thanks for the internals understanding - that makes complete sense. I am the developer :wink: Was able to resolve the issue meantime. Thanks for taking the time to assist :slight_smile:

This thread can definitely be closed now - once again thanks!

Nice! glad to hear that @Robert_Craig :+1:
You’re most welcome! :smile:
Alright, I will close this thread now!