0

I have been running a network of WordPress sites (Multisite) since version 3.8.1. I've been constantly updating plugins and core. At some point, I discovered that uploading new images yields broken results.

When I upload a file it goes to wp-content/blogs.dir/7/files, 7 being the blog id. WordPress, for some reason thinks that it should link to https://siteurl.com/files/file-name.png and therefore all images in Media Library or in newly added content are broken.

I do not recall editing any configuration and previously all files went to the directory e.g. wp-content/uploads/sites/7/files/2015/05/. I was guessing that updating some plugin or core caused the behavior, but as I go in the history through a VCS, I cannot restore the previous upload behavior so it hints that the issue might be caused by file permissions, .htaccess or similar. I did try to play around with those as well, but to no success.

When looking at the source code, I can't figure out how it was working before. There's a line that defines the upload path to be blogs.dir here https://github.com/WordPress/WordPress/blob/master/wp-includes/ms-default-constants.php#L31

I tried overriding these three values

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

with

define( 'UPLOADBLOGSDIR', WP_CONTENT_DIR . '/uploads' ); define( 'UPLOADS', UPLOADBLOGSDIR . "sites/{$wpdb->blogid}/" ); define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/uploads/{$wpdb->blogid}/" ); 

but I cannot get the $wpdb->blogid in the wp-config.php so it doesn't work. And still, I can't figure out how it was working before.

Any thoughts?

P.S Just found out that uploads are working for the top level blog.

P.S2 Tried uploading a file in the top level blog. It shows the link to /wp-content/uploads/2015/05/Screen-Shot-2015-05-29-at-09.56.02.png in media browser. Now when I open /wp-includes/ms-files.php?file=2015/05/Screen-Shot-2015-05-29-at-09.56.02.png I get a 404 and when I echo out the file path ms-files.php is trying to include, I get /wp-content/blogs.dir/1/files/2015/05/Screen-Shot-2015-05-29-at-09.56.02.png

2 Answers 2

0

This line was missing from my .htaccess file, and I recovered it from a backup. I don't know if WP removed it during an upgrade or some other plugin did it, but replacing it fixed the problem:

#uploaded files RewriteRule ^files/(..+) wp-includes/ms-files.php?file=$1 [L] 

Art Smith

0

After an agonising search I found out that somehow the ms_files_rewriting option had been turned on. I've had it off since the install, but in progress of updating something it was set to 1 in db. Setting it back to 0 fixed the issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.