• Hi,
    I have searched the forum to find an answer but could not find one so I am posting a new thread.
    I’m running WordPress 3.3.1 in a Multisite. When I add media from one of the sites, the file gets uploaded and thumbnails are created in the proper directory (blogs.dir/2/files/2012/05/image.jpg) but when looking at the media record the thumbnails are blank and the Filename URL is incorrect.

    Details:
    When I create a post and insert an image the image come inserted following this path:
    https://www.site.com/blogs/wp-content/blogs.dir/2/files/2012/05/image.jpg where the absolute path pointing to visualize the image correctly.

    The problem is that the path entered in the post is as follows:
    https://www.site.com/blogs/bob/files/2012/05/image.jpg il which gives me a 404 – File not found, pointing directly at this location, I can’t display the image in post.

    I have verified that the “Fileupload Url” (in Network Admin>Site>Edit>Settings) is as follows https://www.site.com/blogs/bob/files

    I think the problem probably lies in the following .htaccess:

    RewriteEngine On
    RewriteBase /blogs/
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]

    Any help would be appreciated. I’m very frustated about this problem. Help me!

    Thanks in advance.

    Sara

Viewing 15 replies - 1 through 15 (of 19 total)
  • Thread Starter sarett

    (@sarett)

    UPDATE!

    I made some more investigations and i tried calling directly the ms-files.php from browser (like: https://www.site.com/blogs/wp-includes/ms-files.php) to see if it was accessible (i did already put file permissions to 755).

    I also modified it to echo informations to the page as follows:

    $file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET[ 'file' ] );
    echo($wpdb->blogid);
    echo('</br>');
    echo(BLOGUPLOADDIR);
    echo('</br>');
    echo($_GET[ 'file' ]);
    echo('</br>');
    echo($file);
    echo('</br>');
    if ( !is_file( $file ) ) {
    	status_header( 404 );
    	die( '404 — File not found. xxx' );
    }

    and it echoes me the following informations:

    1
    /var/www/vhosts/site.com/httpdocs/blogs/wp-content/blogs.dir/1/files/

    /var/www/vhosts/site.com/httpdocs/blogs/wp-content/blogs.dir/1/files/
    404 — File not found. xxx

    so i understand the following:
    1) the blog #id used to compose the image path is 1, while my image resides in the blog id #2.
    2) i don’t know if it’s because i’m calling ms-files.php directly and thus completely outside blog context (from where i suppose it may get the right blog #id)
    3) but i can also see it is somewhat working, so at this point i think my htaccess doesn’t have problems and ms-files.php neither.

    So why do i continue getting 404 errors on uploaded images when reading secondary blogs?

    Thread Starter sarett

    (@sarett)

    UPDATE #2:
    again, for testing purposes, i changed the file ms-default-constants.php hardcoding the id #2 in the following line:

    if ( 'wp-content/blogs.dir' == UPLOADBLOGSDIR )
    			//define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/" );
    			define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/2/files/" );

    and i opened my blog #2. Now the problem changed: the 404s were solved, but i got all the images not to be downloaded with firefox console giving me the following error:

    Image corrupt or truncated

    I then went via ftp to the uploading directory and downloaded some of the images, finding that they were completely ok. So i made a search and found out this ticket: https://core.trac.www.ads-software.com/ticket/14730

    I applied the following patch to ms-files.php:

    // If we made it this far, just serve the file
    ob_clean();
    flush();
    readfile( $file );
    flush();

    and now images are showing! But remember, i still have the blog id hardcoded to 2 in ms-default-constants.php

    If i change it back to normal {$wpdb->blogid} the 404s are back.
    ??

    please help me i don’t know what more to do!!!!

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    https://www.site.com/blogs/bob/files/2012/05/image.jpg is the correct URL. Promise. Don’t mess with that.

    See this line?

    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

    That tells /blogs/bob/files/2012/05/image.jpg that it’s really /blogs/wp-includes/ms-files.php?file=/2012/05/image.jpg which is really https://www.site.com/blogs/wp-content/blogs.dir/2/files/2012/05/image.jpg

    So why isn’t it working? 90% of the time it’s because AllowOverride isn’t set to ALL in your httpd.conf.

    Ipstenu. How do I set AllowOverride t ALL ? where do I find the httpd.conf?

    Do you think that it will fix the problem? (got the same as OP)

    Thread Starter sarett

    (@sarett)

    https://www.site.com/blogs/bob/files/2012/05/image.jpg is the correct URL. Promise. Don’t mess with that.

    Hi Ipstenu, thanks for gettin back to me.
    I assure you i won’t absolutely mess with paths.

    I have contacted my web host to verify the AllowOverride option, but i don’t think it is related, because the .htaccess in root folder of the site works without any issue (i think i should specify i have a wordpress installation under a joomla site, so the root directory is the joomla one, and its htaccess file contains the proper rules to make it work, and it DOES work).

    I made sure to check all the things you mentioned in every thread i read on this forum before posting, and the only thing i’d like to know is if the problem emerged on my update #2 could have some explanation or not.

    I only had to change manually the ID of the blog to get the right image url (not messing with paths like you said above i swear!!!), so i think the rewrite is working: it is the part where wp gets the right blog id that fails!!!

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    I have contacted my web host to verify the AllowOverride option, but i don’t think it is related, because the .htaccess in root folder of the site works without any issue

    You’d think, but no. Specifically, your .htaccess is not being read completely. Otherwise it would be showing your image. Trust me ?? Check that first before you start messing with the rest. And I refuse to look at core edits because that way lies madness. Never edit core.

    Your server’s not passing images through wp-includes/ms-files.php correctly.

    This is usually the case of httpd.conf not having AllowOverride to All. The other main reasons are you have PHP in safe_mode, or SuHosin PHP.

    wikkew – Ask your webhost.

    Thread Starter sarett

    (@sarett)

    Webhost confirmed me my AllowOverride is set to All.

    I also passed him my .htaccess for checking if there were some wrong directives and he told me it works 100%.

    safe_mode is OFF and SuHosin is not installed…

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    I may have missed it, but can you provide a link to an image that’s not working correctly?

    Thread Starter sarett

    (@sarett)

    Hi Jan, thanks for your interest.
    I’m sorry but the site owner doesn’t want me to publish links in public forums.

    In the meanwhile I checked something more.

    Since the site is pretty complicated and full of things and modules, i had made a staging site where i configured everything, and then i copied everything (filesystem, db, settings, etc.) into the production site.

    In the staging one, upload of pics and relative showing by posts or by direct link works; in the production one nope (with the problems i described above).

    So i made a diff over files and they are equal in both sites.
    The db is also equal (different only in the primary domain name of course) and permissions over files and directories also are ok on both sides.

    At this point i don’t know where to look for a solution.

    Thread Starter sarett

    (@sarett)

    I forgot to mention that both sites are hosted on the same server under two different domains which i can create and manage through a plesk control panel.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    You did a total mimic right? All the sites and sub-sites?

    Thread Starter sarett

    (@sarett)

    Yes a total mimic one, all sites and subsites, the structure, users, posts, etc.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Pull your .htaccess and make it the default one for WP Multisite?

    Thread Starter sarett

    (@sarett)

    I’m sorry but I don’t think i have understood what you mean.

    My current .htaccess for wp multisite is the following:

    RewriteEngine On
    RewriteBase /blogs/
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    That’s the whole thing?

    Does it look the same as the test site? Except for the /blogs/ bit? ??

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Error image path’ is closed to new replies.