kollapsminoriteten/wp-includes/ms-files.php

101 lines
2.8 KiB
PHP
Raw Normal View History

2019-11-02 10:38:58 +01:00
<?php
/**
* Multisite upload handler.
*
* @since 3.0.0
*
* @package WordPress
* @subpackage Multisite
*/
2022-04-02 10:26:41 +02:00
define( 'MS_FILES_REQUEST', true );
2019-11-02 10:38:58 +01:00
define( 'SHORTINIT', true );
2025-04-25 12:30:07 +02:00
/** Load WordPress Bootstrap */
2020-05-06 17:23:38 +02:00
require_once dirname( __DIR__ ) . '/wp-load.php';
2019-11-02 10:38:58 +01:00
if ( ! is_multisite() ) {
die( 'Multisite support not enabled' );
}
ms_file_constants();
2025-06-09 10:07:10 +02:00
if ( '1' === $current_blog->archived || '1' === $current_blog->spam || '1' === $current_blog->deleted ) {
2019-11-02 10:38:58 +01:00
status_header( 404 );
die( '404 &#8212; File not found.' );
}
2025-12-12 13:15:55 +01:00
if ( ! defined( 'BLOGUPLOADDIR' ) ) {
status_header( 500 );
die( '500 &#8212; Directory not configured.' );
}
2019-11-02 10:38:58 +01:00
$file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET['file'] );
if ( ! is_file( $file ) ) {
status_header( 404 );
die( '404 &#8212; File not found.' );
}
$mime = wp_check_filetype( $file );
if ( false === $mime['type'] && function_exists( 'mime_content_type' ) ) {
$mime['type'] = mime_content_type( $file );
}
if ( $mime['type'] ) {
$mimetype = $mime['type'];
} else {
$mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 );
}
2020-05-06 17:23:38 +02:00
header( 'Content-Type: ' . $mimetype ); // Always send this.
2023-09-26 10:33:34 +02:00
if ( ! str_contains( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) {
2019-11-02 10:38:58 +01:00
header( 'Content-Length: ' . filesize( $file ) );
}
2020-05-06 17:23:38 +02:00
// Optional support for X-Sendfile and X-Accel-Redirect.
2019-11-02 10:38:58 +01:00
if ( WPMU_ACCEL_REDIRECT ) {
header( 'X-Accel-Redirect: ' . str_replace( WP_CONTENT_DIR, '', $file ) );
exit;
} elseif ( WPMU_SENDFILE ) {
header( 'X-Sendfile: ' . $file );
exit;
}
2023-12-07 09:44:11 +01: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 );
2019-11-02 10:38:58 +01:00
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' );
2020-05-06 17:23:38 +02:00
// Support for conditional GET - use stripslashes() to avoid formatting.php dependency.
2023-12-07 09:44:11 +01:00
if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) {
$client_etag = stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] );
} else {
$client_etag = '';
}
2019-11-02 10:38:58 +01:00
2023-12-07 09:44:11 +01:00
if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
$client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
} else {
$client_last_modified = '';
2019-11-02 10:38:58 +01:00
}
2020-05-06 17:23:38 +02:00
// If string is empty, return 0. If not, attempt to parse into a timestamp.
2019-11-02 10:38:58 +01:00
$client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
2023-12-07 09:44:11 +01:00
// Make a timestamp for our most recent modification.
$wp_modified_timestamp = strtotime( $wp_last_modified );
2019-11-02 10:38:58 +01:00
if ( ( $client_last_modified && $client_etag )
2023-12-07 09:44:11 +01:00
? ( ( $client_modified_timestamp >= $wp_modified_timestamp ) && ( $client_etag === $wp_etag ) )
: ( ( $client_modified_timestamp >= $wp_modified_timestamp ) || ( $client_etag === $wp_etag ) )
) {
2019-11-02 10:38:58 +01:00
status_header( 304 );
exit;
}
2020-05-06 17:23:38 +02:00
// If we made it this far, just serve the file.
2019-11-02 10:38:58 +01:00
readfile( $file );
flush();