WordPress.org

Forums

[resolved] How to find the upload path for a blog? MU 2.9.2 (6 posts)

  1. sofaking21
    Member
    Posted 5 years ago #

    I would love to just change themes to one that works, but unfortunately I'm stuck with trying to figure out how to change a theme just enough to make it work in an MU environment.

    On the backend, users are allowed to upload a logo. Unfortunately, all these logo files go into a shared folder so if by some weird chance blog 5 decides to upload "header_image.png" but blog 1 is using that same filename, BOOM! Both blogs now have the same header. Blog 5 is happy, but blog 1 is cranky.

    Here's the troublesome code:

    $directory = dirname(__FILE__)."/uploads/";
    move_uploaded_file($_FILES[$file]["tmp_name"], $directory.$_FILES[$file]["name"]);

    I'm going insane on trying to figure out how to get $directory to point to the proper blogs.dir/blog_id/files/ directory. I have used the get_option('upload_path') which gets me almost everything I need. I just can't figure out how to find the absolute path of the installation directory of WordPress. I'm going nuts trying to figure this out, any help would be greatly appreciated.

  2. spherical
    Member
    Posted 5 years ago #

    What file is the "troublesome code" in? If it really is WPMu 2.9.2, /uploads/ shouldn't be in there. Just searched an archived WPMu 2.9.2 tree and nada.

  3. sofaking21
    Member
    Posted 5 years ago #

    That code is the functions.php of the theme. Easiest solution: change themes, but the powers that be say that's not an option.

  4. I'm wondering why the theme isn't using the built-in header upload, which does toss it in the right spot.

  5. sofaking21
    Member
    Posted 5 years ago #

    You'd be amazed how few themes use the built-in functions. This theme (Intrepidity) allows users to upload a custom header, footer and logo image. Another theme (Arras) does something similar (only allows for a custom logo), but uses the wp_handle_upload hook to upload to the proper blogs.dir/blog_id/files/ folder. I've tried recoding this section of code using that hook and I must've screwed something up pretty good.

    Is there any way to pull the value of WP_CONTENT_DIR that is defined in wp-settings.php?

  6. sofaking21
    Member
    Posted 5 years ago #

    I officially feel dumb. Just in case anyone else ever runs into this type of issue, here's how I solved it:

    $directory = ABSPATH.get_option('uplload_path').'/';

    I don't know why it didn't click to me that since some of these directories are defined as constants, I could just reference them directly.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.