16 die( 'Multisite support not enabled' ); |
16 die( 'Multisite support not enabled' ); |
17 } |
17 } |
18 |
18 |
19 ms_file_constants(); |
19 ms_file_constants(); |
20 |
20 |
21 if ( '1' == $current_blog->archived || '1' == $current_blog->spam || '1' == $current_blog->deleted ) { |
21 if ( '1' === $current_blog->archived || '1' === $current_blog->spam || '1' === $current_blog->deleted ) { |
22 status_header( 404 ); |
22 status_header( 404 ); |
23 die( '404 — File not found.' ); |
23 die( '404 — File not found.' ); |
24 } |
24 } |
25 |
25 |
26 $file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET['file'] ); |
26 $file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET['file'] ); |
39 } else { |
39 } else { |
40 $mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 ); |
40 $mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 ); |
41 } |
41 } |
42 |
42 |
43 header( 'Content-Type: ' . $mimetype ); // Always send this. |
43 header( 'Content-Type: ' . $mimetype ); // Always send this. |
44 if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) { |
44 if ( ! str_contains( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) { |
45 header( 'Content-Length: ' . filesize( $file ) ); |
45 header( 'Content-Length: ' . filesize( $file ) ); |
46 } |
46 } |
47 |
47 |
48 // Optional support for X-Sendfile and X-Accel-Redirect. |
48 // Optional support for X-Sendfile and X-Accel-Redirect. |
49 if ( WPMU_ACCEL_REDIRECT ) { |
49 if ( WPMU_ACCEL_REDIRECT ) { |
52 } elseif ( WPMU_SENDFILE ) { |
52 } elseif ( WPMU_SENDFILE ) { |
53 header( 'X-Sendfile: ' . $file ); |
53 header( 'X-Sendfile: ' . $file ); |
54 exit; |
54 exit; |
55 } |
55 } |
56 |
56 |
57 $last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) ); |
57 $wp_last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) ); |
58 $etag = '"' . md5( $last_modified ) . '"'; |
58 $wp_etag = '"' . md5( $wp_last_modified ) . '"'; |
59 header( "Last-Modified: $last_modified GMT" ); |
59 |
60 header( 'ETag: ' . $etag ); |
60 header( "Last-Modified: $wp_last_modified GMT" ); |
|
61 header( 'ETag: ' . $wp_etag ); |
61 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' ); |
62 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' ); |
62 |
63 |
63 // Support for conditional GET - use stripslashes() to avoid formatting.php dependency. |
64 // Support for conditional GET - use stripslashes() to avoid formatting.php dependency. |
64 $client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false; |
65 if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) { |
65 |
66 $client_etag = stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ); |
66 if ( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) { |
67 } else { |
67 $_SERVER['HTTP_IF_MODIFIED_SINCE'] = false; |
68 $client_etag = ''; |
68 } |
69 } |
69 |
70 |
70 $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); |
71 if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) { |
|
72 $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); |
|
73 } else { |
|
74 $client_last_modified = ''; |
|
75 } |
|
76 |
71 // If string is empty, return 0. If not, attempt to parse into a timestamp. |
77 // If string is empty, return 0. If not, attempt to parse into a timestamp. |
72 $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0; |
78 $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0; |
73 |
79 |
74 // Make a timestamp for our most recent modification... |
80 // Make a timestamp for our most recent modification. |
75 $modified_timestamp = strtotime( $last_modified ); |
81 $wp_modified_timestamp = strtotime( $wp_last_modified ); |
76 |
82 |
77 if ( ( $client_last_modified && $client_etag ) |
83 if ( ( $client_last_modified && $client_etag ) |
78 ? ( ( $client_modified_timestamp >= $modified_timestamp ) && ( $client_etag == $etag ) ) |
84 ? ( ( $client_modified_timestamp >= $wp_modified_timestamp ) && ( $client_etag === $wp_etag ) ) |
79 : ( ( $client_modified_timestamp >= $modified_timestamp ) || ( $client_etag == $etag ) ) |
85 : ( ( $client_modified_timestamp >= $wp_modified_timestamp ) || ( $client_etag === $wp_etag ) ) |
80 ) { |
86 ) { |
81 status_header( 304 ); |
87 status_header( 304 ); |
82 exit; |
88 exit; |
83 } |
89 } |
84 |
90 |
85 // If we made it this far, just serve the file. |
91 // If we made it this far, just serve the file. |