WordPress.org

Ready to get started?Download WordPress

Forums

get_attached_file() returns wrong path? (2 posts)

  1. Måns Jonasson
    Member
    Posted 5 years ago #

    Hey,

    I'm trying to use get_attached_file() in my new plugin to find out the complete path of an uploaded file based on its ID.

    But get_attached_file seems to only return the base URL of uploads, instead of the complete path to the actual file on installations that are using the "organize uploads by year and month" option.

    i.e. get_attached_file() is telling me that the file with ID 1 is located in /home/user/wordpress/wp-content/upload/ instead of where it actually happens to be, which is /home/user/wordpress/wp-content/upload/2008/04/

    Anybody recognize this problem? Or have another solution for me?

    Thanks.

  2. Yofazza
    Member
    Posted 4 years ago #

    I also got ../wp-content/uploads/ from this function. Googled. Found this thread. No solution. Take a closer look, and...

    I did this: echo get_attached_file($foo -> ID); while it should've been this: echo get_attached_file($foo[0] -> ID);.

    --

    $foo = get_posts ('post_type=attachment&post_parent=90');
    echo '<pre>' . print_r ($foo, true) . '</pre>';

    The 2nd line is very helpful to me on many occasions. :p

Topic Closed

This topic has been closed to new replies.

About this Topic