~canonical-sysadmins/wordpress/4.7.2

« back to all changes in this revision

Viewing changes to wp-includes/ms-files.php

  • Committer: Jacek Nykis
  • Date: 2015-01-05 16:17:05 UTC
  • Revision ID: jacek.nykis@canonical.com-20150105161705-w544l1h5mcg7u4w9
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
14
if( !is_multisite() )
 
15
        die( 'Multisite support not enabled' );
 
16
 
 
17
ms_file_constants();
 
18
 
 
19
error_reporting( 0 );
 
20
 
 
21
if ( $current_blog->archived == '1' || $current_blog->spam == '1' || $current_blog->deleted == '1' ) {
 
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
if( $mime[ 'type' ] )
 
37
        $mimetype = $mime[ 'type' ];
 
38
else
 
39
        $mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 );
 
40
 
 
41
header( 'Content-Type: ' . $mimetype ); // always send this
 
42
if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) )
 
43
        header( 'Content-Length: ' . filesize( $file ) );
 
44
 
 
45
// Optional support for X-Sendfile and X-Accel-Redirect
 
46
if ( WPMU_ACCEL_REDIRECT ) {
 
47
        header( 'X-Accel-Redirect: ' . str_replace( WP_CONTENT_DIR, '', $file ) );
 
48
        exit;
 
49
} elseif ( WPMU_SENDFILE ) {
 
50
        header( 'X-Sendfile: ' . $file );
 
51
        exit;
 
52
}
 
53
 
 
54
$last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) );
 
55
$etag = '"' . md5( $last_modified ) . '"';
 
56
header( "Last-Modified: $last_modified GMT" );
 
57
header( 'ETag: ' . $etag );
 
58
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' );
 
59
 
 
60
// Support for Conditional GET - use stripslashes to avoid formatting.php dependency
 
61
$client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false;
 
62
 
 
63
if( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) )
 
64
        $_SERVER['HTTP_IF_MODIFIED_SINCE'] = false;
 
65
 
 
66
$client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
 
67
// If string is empty, return 0. If not, attempt to parse into a timestamp
 
68
$client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
 
69
 
 
70
// Make a timestamp for our most recent modification...
 
71
$modified_timestamp = strtotime($last_modified);
 
72
 
 
73
if ( ( $client_last_modified && $client_etag )
 
74
        ? ( ( $client_modified_timestamp >= $modified_timestamp) && ( $client_etag == $etag ) )
 
75
        : ( ( $client_modified_timestamp >= $modified_timestamp) || ( $client_etag == $etag ) )
 
76
        ) {
 
77
        status_header( 304 );
 
78
        exit;
 
79
}
 
80
 
 
81
// If we made it this far, just serve the file
 
82
readfile( $file );