WordPress Multisite uploads broken images

I am having an issue with one of my sub-sites media library. All it uploads are broken images. It loads fine locally but for some reason it gives me the error

"Failed to load resource: the server responded with a status of 404 (Not Found) http://mjstokes.com/victoria/files/2017/02/model6-150x150.jpg"
Locally all uploads goes into my wp-content/uploads path, but as hosted live they go into my files folder, which is in domain/theme/files. I have already contact my hosting company and they were unable to assist me.

Note: The images are present and the file permissions are set to 755 with owner/group 776 774.

  • Denitsa

    Hey there Michael Stokes,

    Can you then try and install the following plugin - https://wordpress.org/plugins/wp-original-media-path/? It will allow you to modify the ??'Store uploaded files in this folder' and 'Full URL path to files' under Settings -> WP Original Media Path for your subsite.

    From the plugin FAQ section:

    The first is your file uploads without the domain. For example, if your upload folder is at the root of the site and it is called 'my-images' the first field must be filled 'my-images'

    The second field is the full URL to the file uploads. In the previous example, the field looks like this: 'http://www.siteweb.com/my-images'

    Let me know how it goes!

    All thebest,
    Denitsa

  • Michael Stokes

    Doesn't work. For every uploaded images it gives me the following:

    "JQMIGRATE: Migrate is installed, version 1.4.1
    img_300x300_1x8bit_T03L03_GRAY_billiard_balls_a-150x150.png Failed to load resource: the server responded with a status of 404 (Not Found)
    ABC-150x150.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
    3T-150x150.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
    W8WlPlj-150x150.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
    XhZ9jAr-150x150.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
    JR4lk6p-150x150.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
    7k2sino-150x150.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
    4lZaB54-150x150.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
    GvvtutB-150x150.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
    img_300x300_1x8bit_T03L03_GRAY_billiard_balls_a-150x150.png Failed to load resource: the server responded with a status of 404 (Not Found)
    ABC-150x150.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
    3T-150x150.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
    img_300x300_1x8bit_T03L03_GRAY_billiard_balls_a-150x150.png Failed to load resource: the server responded with a status of 404 (Not Found)
    ABC-150x150.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
    3T-150x150.jpg Failed to load resource: the server responded with a status of 404 (Not Found)
    img_300x300_1x8bit_T03L03_GRAY_billiard_balls_a-150x150.png:1 GET http://mjstokes.com/victoria/files/2017/02/img_300x300_1x8bit_T03L03_GRAY_billiard_balls_a-150x150.png 404 (Not Found)
    ABC-150x150.jpg:1 GET http://mjstokes.com/victoria/files/2017/02/ABC-150x150.jpg 404 (Not Found)
    3T-150x150.jpg:1 GET http://mjstokes.com/victoria/files/2017/02/3T-150x150.jpg 404 (Not Found)"

    I followed the documentation for Multisite Image URLs here https://codex.wordpress.org/Multisite_Network_Administration#Uploaded_File_Path

    The images are being uploaded in that same url path. I don't understand why WordPress can find them?

  • Lindeni Mahlalela

    Hello Michael,

    I had a look into your Multisite install and also tried to access the images manually on the browser by copying their direct urls.

    When copying the url of an image and accessing it on the browser it takes me straight to the home page of the subsite where the image belongs to. It does not give an error or a 404 error message. This is a sign that there is something missing in the configuration of your Multisite.

    According to the Multisite documentation , the wp-files.php and .htaccess work together to achieve the url rewriting and redirection to ensure that the folders are referenced properly.

    Would you please verify that all the required settings have been completed and the necessary changes made to the ms-files.php and .htaccess files to achieve the desired output.

    If you haven't done so already, you may find the code to paste in your .htaccess file in your network admin by going to "Settings > Network Setup" and at the bottom, on step 2, you will find the code to paste in your .htaccess file. Verify that the code in this file is the same as the one provided in the network settings and try again uploading the files. Please note that some plugins may add their code to this file as well so make sure you modify between the lines '# BEGIN WordPress' and '# END WordPress', everything outside these lines should be left as is.

    I hope this helps you solve the issue but if you have any more questions or concerns please feel free to ask.

    Cheers,
    Mahlamusa

  • Michael Stokes

    Here is my current ms-files.php

    <?php
    /**
     * Multisite upload handler.
     *
     * @since 3.0.0
     *
     * @package WordPress
     * @subpackage Multisite
     */
    
    define( 'SHORTINIT', true );
    require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
    
    if ( !is_multisite() )
    	die( 'Multisite support not enabled' );
    
    ms_file_constants();
    
    error_reporting( 0 );
    
    if ( $current_blog->archived == '1' || $current_blog->spam == '1' || $current_blog->deleted == '1' ) {
    	status_header( 404 );
    	die( '404 — File not found.' );
    }
    
    $file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET[ 'file' ] );
    if ( !is_file( $file ) ) {
    	status_header( 404 );
    	die( '404 — File not found.' );
    }
    
    $mime = wp_check_filetype( $file );
    if ( false === $mime[ 'type' ] && function_exists( 'mime_content_type' ) )
    	$mime[ 'type' ] = mime_content_type( $file );
    
    if ( $mime[ 'type' ] )
    	$mimetype = $mime[ 'type' ];
    else
    	$mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 );
    
    header( 'Content-Type: ' . $mimetype ); // always send this
    if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) )
    	header( 'Content-Length: ' . filesize( $file ) );
    
    // Optional support for X-Sendfile and X-Accel-Redirect
    if ( WPMU_ACCEL_REDIRECT ) {
    	header( 'X-Accel-Redirect: ' . str_replace( WP_CONTENT_DIR, '', $file ) );
    	exit;
    } elseif ( WPMU_SENDFILE ) {
    	header( 'X-Sendfile: ' . $file );
    	exit;
    }
    
    $last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) );
    $etag = '"' . md5( $last_modified ) . '"';
    header( "Last-Modified: $last_modified GMT" );
    header( 'ETag: ' . $etag );
    header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' );
    
    // Support for Conditional GET - use stripslashes to avoid formatting.php dependency
    $client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false;
    
    if ( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) )
    	$_SERVER['HTTP_IF_MODIFIED_SINCE'] = false;
    
    $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
    // If string is empty, return 0. If not, attempt to parse into a timestamp
    $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
    
    // Make a timestamp for our most recent modification...
    $modified_timestamp = strtotime($last_modified);
    
    if ( ( $client_last_modified && $client_etag )
    	? ( ( $client_modified_timestamp >= $modified_timestamp) && ( $client_etag == $etag ) )
    	: ( ( $client_modified_timestamp >= $modified_timestamp) || ( $client_etag == $etag ) )
    	) {
    	status_header( 304 );
    	exit;
    }
    
    // If we made it this far, just serve the file
    readfile( $file );
    flush();

    Here is the updated .htaccess file

    #BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    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).*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]
    </IfModule>
    
    # END WordPress

    Nothing works. Still uploads broken images.

  • Kasia Swiderska

    Hello Michael,

    I would like to take closer look on your multisite setup. I think there are some puzzles missing here. Could you please send in the following via our secure contact form https://premium.wpmudev.org/contact/ :

    - Mark to my attention, the subject line should contain only: ATTN: Kasia Swiderska
    - Do not include anything else in the subject line, doing so may delay our response due to how email filtering works.
    - Link back to this thread
    - Include WordPress network admin access details (login address, username & password)
    - Include FTP log-in details (hostname, username & password)
    - Include any relevant URLs for your site

    IMPORTANT: Please make sure you select "I have a different question" for your topic, so it doesn't go back to the forums - this and the subject line ensure that it gets assigned to me.

    Please confirm here that you send those credentials

    kind regards,
    Kasia

  • Rupok

    Hi Michael Stokes,

    All it uploads are broken images

    Thanks for providing the FTP and WP Credentials. I logged in with FTP and commented out the following line from your "wp-config.php" file:
    define( 'UPLOADS', 'files' );

    And now new uploaded files are not being broken anymore. I've uploaded two files and both of them are accessible now. Can you please check and confirm?

    Please let me know if I'm missing any point. I'll be glad to help further.

    Have a nice day. Cheers!
    Rupok

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.