2010-01-06 05:02:57 +01:00
|
|
|
<?php
|
2010-02-03 19:19:56 +01:00
|
|
|
/**
|
2010-02-05 22:40:22 +01:00
|
|
|
* Multisite upload handler.
|
2010-02-03 19:19:56 +01:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Multisite
|
|
|
|
*/
|
|
|
|
|
2021-07-06 22:21:57 +02:00
|
|
|
define( 'MS_FILES_REQUEST', true );
|
2010-02-28 21:29:24 +01:00
|
|
|
define( 'SHORTINIT', true );
|
2020-02-06 07:33:11 +01:00
|
|
|
require_once dirname( __DIR__ ) . '/wp-load.php';
|
2010-02-05 22:40:22 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! is_multisite() ) {
|
2010-05-13 23:40:42 +02:00
|
|
|
die( 'Multisite support not enabled' );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2010-05-13 23:40:42 +02:00
|
|
|
|
2010-02-28 21:29:24 +01:00
|
|
|
ms_file_constants();
|
2010-02-03 19:19:56 +01:00
|
|
|
|
2020-02-09 17:55:09 +01:00
|
|
|
if ( '1' == $current_blog->archived || '1' == $current_blog->spam || '1' == $current_blog->deleted ) {
|
2010-01-06 05:02:57 +01:00
|
|
|
status_header( 404 );
|
2010-02-03 19:19:56 +01:00
|
|
|
die( '404 — File not found.' );
|
2010-01-06 05:02:57 +01:00
|
|
|
}
|
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET['file'] );
|
|
|
|
if ( ! is_file( $file ) ) {
|
2010-01-06 05:02:57 +01:00
|
|
|
status_header( 404 );
|
2010-02-03 19:19:56 +01:00
|
|
|
die( '404 — File not found.' );
|
2010-01-06 05:02:57 +01:00
|
|
|
}
|
|
|
|
|
2010-10-07 23:00:45 +02:00
|
|
|
$mime = wp_check_filetype( $file );
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( false === $mime['type'] && function_exists( 'mime_content_type' ) ) {
|
|
|
|
$mime['type'] = mime_content_type( $file );
|
|
|
|
}
|
2010-01-06 05:02:57 +01:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( $mime['type'] ) {
|
|
|
|
$mimetype = $mime['type'];
|
|
|
|
} else {
|
2010-10-07 23:00:45 +02:00
|
|
|
$mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2010-02-03 19:19:56 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
header( 'Content-Type: ' . $mimetype ); // Always send this.
|
Code Modernization: Replace usage of `strpos()` with `str_contains()`.
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).
WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.
This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.
Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].
Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.
Built from https://develop.svn.wordpress.org/trunk@55988
git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-22 16:36:26 +02:00
|
|
|
if ( ! str_contains( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) {
|
2010-02-03 19:19:56 +01:00
|
|
|
header( 'Content-Length: ' . filesize( $file ) );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2010-01-06 05:02:57 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Optional support for X-Sendfile and X-Accel-Redirect.
|
2010-02-03 19:19:56 +01:00
|
|
|
if ( WPMU_ACCEL_REDIRECT ) {
|
|
|
|
header( 'X-Accel-Redirect: ' . str_replace( WP_CONTENT_DIR, '', $file ) );
|
2010-01-06 05:02:57 +01:00
|
|
|
exit;
|
2010-02-03 19:19:56 +01:00
|
|
|
} elseif ( WPMU_SENDFILE ) {
|
|
|
|
header( 'X-Sendfile: ' . $file );
|
2010-01-06 05:02:57 +01:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2023-08-13 12:31:23 +02:00
|
|
|
$wp_last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) );
|
|
|
|
$wp_etag = '"' . md5( $wp_last_modified ) . '"';
|
|
|
|
|
|
|
|
header( "Last-Modified: $wp_last_modified GMT" );
|
|
|
|
header( 'ETag: ' . $wp_etag );
|
2010-02-03 19:19:56 +01:00
|
|
|
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' );
|
2010-01-06 05:02:57 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Support for conditional GET - use stripslashes() to avoid formatting.php dependency.
|
2023-08-13 12:31:23 +02:00
|
|
|
if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) {
|
|
|
|
$client_etag = stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] );
|
|
|
|
} else {
|
|
|
|
$client_etag = '';
|
|
|
|
}
|
2010-01-06 05:02:57 +01:00
|
|
|
|
2023-08-13 12:31:23 +02:00
|
|
|
if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
|
|
|
|
$client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
|
|
|
|
} else {
|
|
|
|
$client_last_modified = '';
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2010-02-03 19:19:56 +01:00
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// If string is empty, return 0. If not, attempt to parse into a timestamp.
|
2010-02-03 19:19:56 +01:00
|
|
|
$client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
|
2010-01-06 05:02:57 +01:00
|
|
|
|
2023-08-13 12:31:23 +02:00
|
|
|
// Make a timestamp for our most recent modification.
|
|
|
|
$wp_modified_timestamp = strtotime( $wp_last_modified );
|
2010-01-06 05:02:57 +01:00
|
|
|
|
2010-02-03 19:19:56 +01:00
|
|
|
if ( ( $client_last_modified && $client_etag )
|
2023-08-13 12:31:23 +02:00
|
|
|
? ( ( $client_modified_timestamp >= $wp_modified_timestamp ) && ( $client_etag === $wp_etag ) )
|
|
|
|
: ( ( $client_modified_timestamp >= $wp_modified_timestamp ) || ( $client_etag === $wp_etag ) )
|
|
|
|
) {
|
2010-01-06 05:02:57 +01:00
|
|
|
status_header( 304 );
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// If we made it this far, just serve the file.
|
2010-01-06 05:02:57 +01:00
|
|
|
readfile( $file );
|
2016-09-27 22:05:28 +02:00
|
|
|
flush();
|