Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

http://localhost/wp-content/uploads/2011/06/sample.jpg

And I want to get the path, like:

/Applications/XAMPP/htdocs/wp-content/uploads/2011/06/sample.jpg

Thanks, Marcos.

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

share|improve this question

2 Answers 2

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

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

Your Answer

 
discard

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.