The following function can be used to get the absolute path to the WordPress uploads directory:
<?php | |
/** | |
* Get the absolute path to the WordPress uploads directory, | |
* with a trailing slash. | |
* | |
* @return string The uploads directory path. | |
*/ | |
function km_get_wordpress_uploads_directory_path() { | |
$upload_dir = wp_upload_dir(); | |
return trailingslashit( $upload_dir['basedir'] ); | |
} |
It will return a path to where the WordPress /uploads/
directory is, whether it’s in the default location or whether an UPLOADS
constant has been defined to specify an alternate location. The path it returns will look something like:
/path/to/wordpress/wp-content/uploads/
Written by Kellen Mace, who lives in Rochester Hills, MI and builds cool stuff on the web. About Kellen // Follow him on Twitter →