WordPress.org

Support

Support » Plugins and Hacks » get_attached_file() returns wrong path?

get_attached_file() returns wrong path?

  • 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.

Viewing 1 replies (of 1 total)
  • 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

Viewing 1 replies (of 1 total)
  • The topic ‘get_attached_file() returns wrong path?’ is closed to new replies.
Skip to toolbar