I have some folder with images in /wp-content/uploads
. I also have a plugin file in /wp-content/plugins
. I want to retrieve the images stored in /wp-content/uploads
and use them in the plugin file.
I have tried
echo'<img src="../../USER_PHOTOS/ronny'" href="#"></img>';
can someone show me how I can get the path to these images?
thanks.
If I’m not mistaken, you may want to try the wp_uploads_dir function, like so:
Unfortunately there is a documented bug where
wp_upload_dir()
does not honor https (ssl). My suggestion is to write a wrapper to remove the protocol from the returned URL to make it adaptable to the environment:If you are concerned about the performance hit of using
preg_replace()
multiple times, then set a constant in your functions.php file:Dan S points out a trac ticket where
wp_upload_dir()
does not support https. I’ve not found this to be the case on my sites, but if it does affect you, then you can add a filter toupload_dir
and manually return the correct protocol based on theis_ssl()
conditional.Then you can continue using
wp_upload_dir()
as you always have.As noted here, unless you have specific performance concerns you should use https://.
I found the answer. I used
wp_upload_dir();
wordpress codexThis is what I used to access an image file named “rock_01.jpg” uploaded to the wordpress folder “uploads/complete-theme/”
It worked as expected.