[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> ms-files.php (source)

   1  <?php
   2  /**
   3   * Multisite upload handler.
   4   *
   5   * @since 3.0.0
   6   *
   7   * @package WordPress
   8   * @subpackage Multisite
   9   */
  10  
  11  define( 'MS_FILES_REQUEST', true );
  12  define( 'SHORTINIT', true );
  13  
  14  /** Load WordPress Bootstrap */
  15  require_once dirname( __DIR__ ) . '/wp-load.php';
  16  
  17  if ( ! is_multisite() ) {
  18      die( 'Multisite support not enabled' );
  19  }
  20  
  21  ms_file_constants();
  22  
  23  if ( '1' === $current_blog->archived || '1' === $current_blog->spam || '1' === $current_blog->deleted ) {
  24      status_header( 404 );
  25      die( '404 &#8212; File not found.' );
  26  }
  27  
  28  if ( ! defined( 'BLOGUPLOADDIR' ) ) {
  29      status_header( 500 );
  30      die( '500 &#8212; Directory not configured.' );
  31  }
  32  
  33  if ( ! isset( $_GET['file'] ) || ! is_string( $_GET['file'] ) ) {
  34      status_header( 404 );
  35      die( '404 &#8212; File not found.' );
  36  }
  37  
  38  $file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET['file'] );
  39  if ( ! is_file( $file ) ) {
  40      status_header( 404 );
  41      die( '404 &#8212; File not found.' );
  42  }
  43  
  44  $mime = wp_check_filetype( $file );
  45  if ( false === $mime['type'] && function_exists( 'mime_content_type' ) ) {
  46      $mime['type'] = mime_content_type( $file );
  47  }
  48  
  49  if ( $mime['type'] ) {
  50      $mimetype = $mime['type'];
  51  } else {
  52      $mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 );
  53  }
  54  
  55  header( 'Content-Type: ' . $mimetype ); // Always send this.
  56  if ( ! str_contains( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) {
  57      header( 'Content-Length: ' . filesize( $file ) );
  58  }
  59  
  60  // Optional support for X-Sendfile and X-Accel-Redirect.
  61  if ( WPMU_ACCEL_REDIRECT ) {
  62      header( 'X-Accel-Redirect: ' . str_replace( WP_CONTENT_DIR, '', $file ) );
  63      exit;
  64  } elseif ( WPMU_SENDFILE ) {
  65      header( 'X-Sendfile: ' . $file );
  66      exit;
  67  }
  68  
  69  $wp_last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) );
  70  $wp_etag          = '"' . md5( $wp_last_modified ) . '"';
  71  
  72  header( "Last-Modified: $wp_last_modified GMT" );
  73  header( 'ETag: ' . $wp_etag );
  74  header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' );
  75  
  76  // Support for conditional GET - use stripslashes() to avoid formatting.php dependency.
  77  if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) {
  78      $client_etag = stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] );
  79  } else {
  80      $client_etag = '';
  81  }
  82  
  83  if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
  84      $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
  85  } else {
  86      $client_last_modified = '';
  87  }
  88  
  89  // If string is empty, return 0. If not, attempt to parse into a timestamp.
  90  $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
  91  
  92  // Make a timestamp for our most recent modification.
  93  $wp_modified_timestamp = strtotime( $wp_last_modified );
  94  
  95  if ( ( $client_last_modified && $client_etag )
  96      ? ( ( $client_modified_timestamp >= $wp_modified_timestamp ) && ( $client_etag === $wp_etag ) )
  97      : ( ( $client_modified_timestamp >= $wp_modified_timestamp ) || ( $client_etag === $wp_etag ) )
  98  ) {
  99      status_header( 304 );
 100      exit;
 101  }
 102  
 103  // If we made it this far, just serve the file.
 104  readfile( $file );
 105  flush();


Generated : Wed Nov 25 08:20:01 2026 Cross-referenced by PHPXref