WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multi-Site wp_handle_upload bug? (14 posts)

  1. pruma
    Member
    Posted 2 years ago #

    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;
    				}
  2. 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.

  3. pruma
    Member
    Posted 2 years ago #

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

  4. 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 ;)

  5. pruma
    Member
    Posted 2 years ago #

    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.

  6. Without a concrete example, I'm not 100% sure what you mean by 'wrong URL'

  7. pruma
    Member
    Posted 2 years ago #

    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]

  8. Can you put the code on pastebin?

  9. pruma
    Member
    Posted 2 years ago #

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

    http://pastebin.com/PiudDZbL

  10. 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/.

  11. pruma
    Member
    Posted 2 years ago #

    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.

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

  13. pruma
    Member
    Posted 2 years ago #

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

  14. pruma
    Member
    Posted 2 years ago #

    Thx, I mark it as resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.