WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

my first question is ...

I want to retrieve path of an upload image. Important: The image isn't atached of any post. I have image url like:


And I want to get the path, like:


Thanks, Marcos.

*I'm trying to improve my English. Sorry.

share|improve this question

This is not very reliable in general (especially not in multisite environment), but for specific case it can be good enough:

$url = 'http://localhost/wp-content/uploads/2011/06/sample.jpg';
$uploads = wp_upload_dir();
$path = str_replace( $uploads['baseurl'], $uploads['basedir'], $url);
share|improve this answer

If you have the attachment ID, you can just use get_attached_file($attachment_id) in WP Core which is reliable in general, unless you have some other plugin mucking with the uploads directory path

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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