author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 16 | a86126ab1dd4 |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Multisite upload handler. |
|
4 |
* |
|
5 |
* @since 3.0.0 |
|
6 |
* |
|
7 |
* @package WordPress |
|
8 |
* @subpackage Multisite |
|
9 |
*/ |
|
10 |
||
19 | 11 |
define( 'MS_FILES_REQUEST', true ); |
0 | 12 |
define( 'SHORTINIT', true ); |
16 | 13 |
require_once dirname( __DIR__ ) . '/wp-load.php'; |
0 | 14 |
|
9 | 15 |
if ( ! is_multisite() ) { |
0 | 16 |
die( 'Multisite support not enabled' ); |
9 | 17 |
} |
0 | 18 |
|
19 |
ms_file_constants(); |
|
20 |
||
16 | 21 |
if ( '1' == $current_blog->archived || '1' == $current_blog->spam || '1' == $current_blog->deleted ) { |
0 | 22 |
status_header( 404 ); |
23 |
die( '404 — File not found.' ); |
|
24 |
} |
|
25 |
||
9 | 26 |
$file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET['file'] ); |
27 |
if ( ! is_file( $file ) ) { |
|
0 | 28 |
status_header( 404 ); |
29 |
die( '404 — File not found.' ); |
|
30 |
} |
|
31 |
||
32 |
$mime = wp_check_filetype( $file ); |
|
9 | 33 |
if ( false === $mime['type'] && function_exists( 'mime_content_type' ) ) { |
34 |
$mime['type'] = mime_content_type( $file ); |
|
35 |
} |
|
0 | 36 |
|
9 | 37 |
if ( $mime['type'] ) { |
38 |
$mimetype = $mime['type']; |
|
39 |
} else { |
|
0 | 40 |
$mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 ); |
9 | 41 |
} |
0 | 42 |
|
16 | 43 |
header( 'Content-Type: ' . $mimetype ); // Always send this. |
9 | 44 |
if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) { |
0 | 45 |
header( 'Content-Length: ' . filesize( $file ) ); |
9 | 46 |
} |
0 | 47 |
|
16 | 48 |
// Optional support for X-Sendfile and X-Accel-Redirect. |
0 | 49 |
if ( WPMU_ACCEL_REDIRECT ) { |
50 |
header( 'X-Accel-Redirect: ' . str_replace( WP_CONTENT_DIR, '', $file ) ); |
|
51 |
exit; |
|
52 |
} elseif ( WPMU_SENDFILE ) { |
|
53 |
header( 'X-Sendfile: ' . $file ); |
|
54 |
exit; |
|
55 |
} |
|
56 |
||
57 |
$last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) ); |
|
9 | 58 |
$etag = '"' . md5( $last_modified ) . '"'; |
0 | 59 |
header( "Last-Modified: $last_modified GMT" ); |
60 |
header( 'ETag: ' . $etag ); |
|
61 |
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' ); |
|
62 |
||
16 | 63 |
// Support for conditional GET - use stripslashes() to avoid formatting.php dependency. |
0 | 64 |
$client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false; |
65 |
||
9 | 66 |
if ( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) { |
0 | 67 |
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = false; |
9 | 68 |
} |
0 | 69 |
|
70 |
$client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); |
|
16 | 71 |
// If string is empty, return 0. If not, attempt to parse into a timestamp. |
0 | 72 |
$client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0; |
73 |
||
74 |
// Make a timestamp for our most recent modification... |
|
9 | 75 |
$modified_timestamp = strtotime( $last_modified ); |
0 | 76 |
|
77 |
if ( ( $client_last_modified && $client_etag ) |
|
9 | 78 |
? ( ( $client_modified_timestamp >= $modified_timestamp ) && ( $client_etag == $etag ) ) |
79 |
: ( ( $client_modified_timestamp >= $modified_timestamp ) || ( $client_etag == $etag ) ) |
|
0 | 80 |
) { |
81 |
status_header( 304 ); |
|
82 |
exit; |
|
83 |
} |
|
84 |
||
16 | 85 |
// If we made it this far, just serve the file. |
0 | 86 |
readfile( $file ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
87 |
flush(); |