WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Media Upload's URL issues, my findings. (8 posts)

  1. ClaudeN
    Member
    Posted 2 years ago #

    THIS IS INFORMATIONAL, NOT A SUPPORT REQUEST. (but if you have comments, by all means, do)

    I just spent more than a few days "rubikubing" with plugins and WordPress's core to solve a discriptancy in the behaviour of the Media Uploader between Main site and Secondary site, in a multisite setup (obviously), with regards to the URLs it gives back, as well as with the files saved in the respective upload paths.

    I have finaly solved my issue by modifying one (1) line of code in the core:
    file: wp-includes/functions.php
    function wp_upload_dir
    line: $main_override = is_multisite() && defined( 'MULTISITE' ); // && is_main_site();

    Notice the commented "&& is_main_site();" at the end?

    I have not found the relevance in this condition testing. But, obviously there must be one, or perhaps it is a forgotten memory bit from the past which has lost its purpose.

    Anyway, that's solves my issue, for now.

    I am providing you with my test results, between an unmodified and modified version. (I tried to keep it short. Yes I did). I hope it helps.

    Thank you WordPress & keep the good work.

    Kind regards
    Claude

    =======================
    Tested with WordPress 3.2.1 and 3.3
    Conditions in both, unmodified & modified, tests:

    xampp server. (same results on live web server)
    all plugins deactivated
    Both Media Settings equal.

    MAIN site's upload path: blog.1/images/
    permalink = /%year%/%postname%/

    SECONDARY site's upload path: blog.3/images/
    permalink = /%category%/%postname%/

    ~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    Test with WordPress 3.3 UN-modified

    ==============
    MAIN site:
    uploaded in MAIN site, from Media -> Add New. File is copied in blog.1/images
    default File URL: http://www.main-site.x/blog.1/images/picture.jpg

    uploaded in MAIN site, from within a post. File is copied in blog.1/images
    default link URL: http://www.main-site.x/blog.1/images/picture.jpg
    request file URL: http://www.main-site.x/blog.1/images/picture.jpg
    request Attachment Post URL: http://www.main-site.x/?attachment_id=1247

    files created (same in both previous uploads):
    picture-150x112.jpg
    picture-150x150.jpg
    picture-300x225.jpg
    picture-350x350.jpg
    picture.jpg

    ==============
    SECONDARY site
    uploaded in secondary site, from Media -> Add New. File is copied in blog.3/images
    default File URL: http://www.secondary.x/files/picture.jpg

    uploaded in secondary site, from within a post. File is copied in blog.3/images
    default link URL: http://www.secondary.x/files/picture.jpg
    request file URL: http://www.secondary.x/files/picture.jpg
    request Attachment Post URL: http://www.secondary.x/bits-n-pieces/test-2/attachment/picture/

    files created (same in both previous uploads):
    picture-150x112.jpg
    picture.jpg

    ~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    Test with WordPress 3.3 Modified

    ==============
    MAIN SITE
    uploaded in secondary site, from Media -> Add New. File is copied in blog.1/images
    default File URL: http://www.main-site.x/blog.1/images/picture.jpg

    uploaded in MAIN site, from within a post. File is copied in blog.1/images
    default link URL: http://www.main-site.x/?attachment_id=1254
    request file URL: http://www.main-site.x/blog.1/images/picture.jpg
    request Attachment Post URL: http://www.main-site.x/?attachment_id=1254

    files created (same in both previous uploads):
    picture-150x112.jpg
    picture-150x150.jpg
    picture-300x225.jpg
    picture-350x350.jpg
    picture.jpg

    ==============
    SECONDARY SITE
    uploaded in secondary site, from Media -> Add New. File is copied in blog.3/images
    default File URL: http://www.secondary.x/blog.3/images/picture.jpg

    uploaded in secondary site, from within a post. File is copied in blog.3/images
    default link URL: http://www.secondary.x/?attachment_id=54
    request file URL: http://www.secondary.x/blog.3/images/picture.jpg
    request Attachment Post URL: http://www.secondary.x/?attachment_id=54

    files created (same in both previous uploads):
    picture-150x112.jpg
    picture-150x150.jpg
    picture-300x225.jpg
    picture-350x350.jpg
    picture-75x75.jpg
    picture.jpg

    END OF TEST RESULTS

  2. ClaudeN
    Member
    Posted 2 years ago #

    I realise the issues/differences might not be obvious... let me re-phrase:

    The issues occur with the secondary site.
    1. the Upload path URL is not passed as with the main site.
    2. the "/files/" in the resulting URL leads nowhere (in my tests)
    3. the file is not copied in multiple sizes as with the main site.

    I hope that clarifies.
    Kind regards
    Claude.

  3. 2. the "/files/" in the resulting URL leads nowhere (in my tests)

    That means your server's not setup correctly. This is how it's SUPPOSE to work:

    1. You go to subsite.domain.com and upload an image.
    2. It gives the URL of subsite.domain.com/files/2011/12/27/foo.jpg
    3. Your .htaccess says 'Aha! that means I use my ms-files.php code instead!' and points that to subsite.domain.com/wp-includes/ms-files.php?file=/2011/12/27/foo.jpg
    4. THAT file says "Subsite == blog ID 3, so the REAL URL is domain.com/wp-content/blogs.dir/3/files//2011/12/27/foo.jpg "

    And that's how you get the image.

    Now, step 3 can cause problems, because if your httpd.conf isn't set to allowOverride ALL then it goes weird. Also if it's not making the images in resized, you probably have a PHP or folder permission error in the wp-content/blogs.dir folder.

  4. ClaudeN
    Member
    Posted 2 years ago #

    (NOT A SUPPORT REQUEST)

    Hello IPSTENU,

    thx for your rrrapidissimo reply. (Were you waiting for my post??)

    a. I've build a fresh test env in xampp, in multisite. And it did work as you specified. congrat!

    b. the issue was not with .htaccess, neither with the httpd.conf but with the site option "Fileupload Url".

    c. but thx for bringing .htaccess up, I finally connected the dots between:
    1. the /files/ line in .htaccess
    2. my failure to install in multisite with the main site not having the "www" at the beginning
    3. the is_main_site function
    4. the image URL with /files/

    I think I have now a better understanding of the concept of multisite in WordPress. One main WWW blog with its /upload/ folder then, all the other blogs with their /blog.dir/x/ folders.

    But then, there are the site options: Upload Path, Upload Url Path, Fileupload Url. I mis-interpreted them as a possiblity to implement a different folder structure. Tricky.

    So, to anybody reading this post, beware of the consequences of modifying the "Fileupload Url" site option in a multisite setup.

    thx again for you insight.
    Kind regards
    Claude.

  5. I know it's not a support request :D

    I felt you deserved an explanation of how it's all supposed to work :) It totally sounded like you didn't make that files link connection which took me a while to grok as well, and I'm a pretty htaccess savvy lady. Also now you know how we debug things ;)

    Yeah, the lesson to remember is 'Don't edit any SETTING if you aren't sure what you're doing.'

    The Upload Path, Upload Url Path, Fileupload Url mishegas is confusing as all get out, and it'll make you crazy.

    (BTW - I don't recommend using www in your domain name on WordPress. If you set up DNS and vhosts correctly, they mean the same thing, and non-www is shorter. And shorter is better)

  6. ClaudeN
    Member
    Posted 2 years ago #

    Well you're a funny lady! ;P

    Much to accomplish and little time to really dig in and become a specialist in everything, there is simply tooooo much. If you were in computer sciences in the 80's then you know how exponencialy it has evolved and how overwhelming it can be.

    Anyhow... I connected enough dots to add a filter function so I can leave WordPress's core alone, I prefer that. Now I can have a flaten folder structure as I wished, without distinguishing between mainsite and secondary sites. And bypassing the ms_files (/files/). Time/use will tell me if I really understand as I think I do. :)

    As for the WWW on the main site. I did try twice to setup with a.site.x then create b.site.x and failed login in admin on the B site. I did a firebug in the php code, down to the cooky not being created properly. Then remembered I had the same problem a year ago. So, I did a 3rd setup with http://www.site.x then created b.site.x, all went perfect, no glitch. I have no idea if it's related to the xampp env or some other obscure fenomenon. But I managed and will leave it at that cause I have other priorities to fullfil.

    Again, thx, really nice chatin with ya.

    Kind regards,
    Claude.

  7. szysz
    Member
    Posted 1 year ago #

    This solution does not work after the update to version 3.4.2 - do you have any ideas?

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    Please post your own topic. This one references an earlier version of WordPress.

Topic Closed

This topic has been closed to new replies.

About this Topic