Support » Networking WordPress » Multi-Site wp_handle_upload bug?

  • Resolved pruma

    (@pruma)


    I’m working on plugin, which should allow front-end picture-updates.

    I ran into two problems, which might be a bug (perhaps some thoughts i didn’t consider). If you use wp_handle_upload and wp_insert_attachment you have to add guid in the attachment array, otherwise it’s not added (#1). Unfortunately if you use the array returned from wp_handle_upload, the url points to mu-blogurl . /files/ etc.
    This is alright if you haven’t been messing with the .htacess but if you using e.g. user-access-manager plugin it doesn’t work.

    For me I solved this with the following code:

    if(is_multisite()) {
    					$corrected = "";
    					$corrected .=  substr($file_return['url'], 0, strpos($file_return['url'], "/files/"));
    					$corrected .=  substr($file_return['file'], strpos($file_return['file'], "/wp-content/"));
    					// return array form wp_handle_upload
    					$file_return['url'] = $corrected;
    				}

Viewing 13 replies - 1 through 13 (of 13 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    So … If you change the normal, expected settings, things don’t work?

    Files should ALWAYS work, and you’re going to run into issues as MultiSite progresses and handles that differently in the future. I’d been leery about that change.

    What did you do to remove the /files/ from .htaccess and why? Maybe there’s a better way around that.

    Thread Starter pruma

    (@pruma)

    Yes, I think there should be a better way, but it works for me. Of course I would like to set it to a generalised way.

    The point is, I don’t want those pictures to be publicly viewable and I think UAM is configuring the .htaccess configuration.
    When disabling this plugin, though having the wrong URL it is shown an viewable, that’s why I thought there must be a redirect in the standard .htaccess (I am not too familiar with those Rewrite Rules).

    Nevertheless I think the return url of:
    $file_return = wp_handle_upload($_FILES[$key], array('test_form' => false));
    is wrong since the it’s pointing to the /files/ directory, though the file is saved in the blog.dir (like the ‘file’ value shows and as it is on the computer).

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Rule 1: If you’re not familiar with the Rewrite Rules, then you do not know better than WordPress, and you need to leave them alone.

    Rule 2: If you’re using plugins you think are affecting things, you need to tell us in your post 🙂

    The point is, I don’t want those pictures to be publicly viewable

    You mean you don’t want people to be able to trawl down into the blogs.dir and find them? That is, literally, one line in the top of your .htaccess

    Options -Indexes

    People can still hit the image if they know its location, but that’s sort of a requirement for the net 😉

    Thread Starter pruma

    (@pruma)

    concerning Rule 1, i totally agree (though i believe as long as it isn’t in production you should mess with everything ;))

    concerning Rule II: well i think the plugin is working fine (and is hiding those pictures completely, no thumbnails or anything visible). Only if given the wrong guid its not working (which seems perfectly fine for me). Btw if using the normal media library upload the guid in the db is fine too.

    But it bothers me. When I find time, I’ll try to skim through the code and find why the wrong url is given.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Without a concrete example, I’m not 100% sure what you mean by ‘wrong URL’

    Thread Starter pruma

    (@pruma)

    if you interested, here is the part of code, with the correction. But as I said I think the Return array of the wp_handle_upload should really give back a different url.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Can you put the code on pastebin?

    Thread Starter pruma

    (@pruma)

    mmm, I didn’t read the all of the forum rules.

    http://pastebin.com/PiudDZbL

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Return array of the wp_handle_upload should really give back a different url.

    Yeah, I don’t get what you mean by that (and I can’t get to pastebin right now, don’t ask).

    is wrong since the it’s pointing to the /files/ directory, though the file is saved in the blog.dir (like the ‘file’ value shows and as it is on the computer).

    THAT is not wrong. It’s 100% correct and as it should be. Your URLs for uploads are always ‘acting’ like they’re in the virtual directory, /files/.

    Thread Starter pruma

    (@pruma)

    that might be, but since e.g. the normal media library upload (via wp-admin) adds the /blog.dir/… url and it’s only working with that, how else could I get that guid into the db when uploading via home-made script.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    but since e.g. the normal media library upload (via wp-admin) adds the /blog.dir/… url

    Adds .. where? All of mine say ipstenu.org/files/…. The main site uses wp-content/uploads, mind you, on any new installs.

    Thread Starter pruma

    (@pruma)

    you’re right, tried it on a brand new install. So this is seems to be a UAM issue …

    Thread Starter pruma

    (@pruma)

    Thx, I mark it as resolved.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Multi-Site wp_handle_upload bug?’ is closed to new replies.