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