Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

The deployment of this and a couple of other blogs I am currently working on was delayed as I struggled with the “broken image” issue most people have been¬†encountering when deploying a multi-site WordPress 3.1 blog to a Windows IIS7 based web-server. There are some really good articles out there going into great detail about getting WP to work reliably with IIS7, especially using the¬†URLRewrite add-on for IIS to emulate the usual .htaccess rules you would use with Apache.

However, no matter what I did, I could not get rid of the broken image problem on all of the networked blogs, only the main “parent” blog was working correctly. In the end, I managed to track the issue down to the PHP script that acts as a proxy for all media file folders within the blogs.dir directory structure for each distinct network blog (wordpress/wp-includes/ms-files.php). I discovered that when serving an image via the proxy script, the content size was 2 bytes longer than when serving the image via it’s direct URL. This led me to the solution. Something in the process within ms-files.php is writing 2 bytes of data to the output stream before loading and streaming the target media file, so by clearing the buffer before streaming the content fixes the problem.

Here is the change that needs to be made, just add lines 82 and 83 to flush the buffer before streaming the target content:

74
75
76
77
78
79
80
81
82
83
84
85
86
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;
}
 
ob_clean();
flush();
 
// If we made it this far, just serve the file
readfile( $file );
Share