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 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 and, I then saved that php file under my
include( 'wp-load.php' );
$upload_dir = wp_upload_dir(); // Array of key => value pairs
$upload_dir now contains something like the following (if successful)
[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
[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:
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
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
/www/kinsta/public/framerpress/wp-content/uploads/ ) in your custom script to make it work correctly/properly . 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 Was able to resolve the issue meantime. Thanks for taking the time to assist
This thread can definitely be closed now - once again thanks!
Nice! glad to hear that @Robert_Craig
You’re most welcome!
Alright, I will close this thread now!