0

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.

2

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);
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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