[ Index ]

PHP Cross Reference of WordPress

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  require_once dirname( __DIR__ ) . '/wp-load.php';
  14  
  15  if ( ! is_multisite() ) {
  16      die( 'Multisite support not enabled' );
  17  }
  18  
  19  ms_file_constants();
  20  
  21  if ( '1' == $current_blog->archived || '1' == $current_blog->spam || '1' == $current_blog->deleted ) {
  22      status_header( 404 );
  23      die( '404 &#8212; File not found.' );
  24  }
  25  
  26  $file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET['file'] );
  27  if ( ! is_file( $file ) ) {
  28      status_header( 404 );
  29      die( '404 &#8212; File not found.' );
  30  }
  31  
  32  $mime = wp_check_filetype( $file );
  33  if ( false === $mime['type'] && function_exists( 'mime_content_type' ) ) {
  34      $mime['type'] = mime_content_type( $file );
  35  }
  36  
  37  if ( $mime['type'] ) {
  38      $mimetype = $mime['type'];
  39  } else {
  40      $mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 );
  41  }
  42  
  43  header( 'Content-Type: ' . $mimetype ); // Always send this.
  44  if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) {
  45      header( 'Content-Length: ' . filesize( $file ) );
  46  }
  47  
  48  // Optional support for X-Sendfile and X-Accel-Redirect.
  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 ) );
  58  $etag          = '"' . md5( $last_modified ) . '"';
  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  
  63  // Support for conditional GET - use stripslashes() to avoid formatting.php dependency.
  64  $client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false;
  65  
  66  if ( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
  67      $_SERVER['HTTP_IF_MODIFIED_SINCE'] = false;
  68  }
  69  
  70  $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
  71  // If string is empty, return 0. If not, attempt to parse into a timestamp.
  72  $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
  73  
  74  // Make a timestamp for our most recent modification...
  75  $modified_timestamp = strtotime( $last_modified );
  76  
  77  if ( ( $client_last_modified && $client_etag )
  78      ? ( ( $client_modified_timestamp >= $modified_timestamp ) && ( $client_etag == $etag ) )
  79      : ( ( $client_modified_timestamp >= $modified_timestamp ) || ( $client_etag == $etag ) )
  80      ) {
  81      status_header( 304 );
  82      exit;
  83  }
  84  
  85  // If we made it this far, just serve the file.
  86  readfile( $file );
  87  flush();


Generated: Thu Apr 18 01:00:02 2024 Cross-referenced by PHPXref 0.7.1