2010-01-05 23:02:57 -05:00
|
|
|
<?php
|
2010-02-03 13:19:56 -05:00
|
|
|
/**
|
2010-02-05 16:40:22 -05:00
|
|
|
* Multisite upload handler.
|
2010-02-03 13:19:56 -05:00
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Multisite
|
|
|
|
*/
|
|
|
|
|
2010-02-05 16:40:22 -05:00
|
|
|
if ( ! defined( 'SHORTINIT' ) ) {
|
|
|
|
define( 'SHORTINIT', true );
|
|
|
|
require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
|
|
|
|
}
|
|
|
|
|
2010-02-03 13:19:56 -05:00
|
|
|
ms_default_constants( 'ms-files' );
|
|
|
|
|
|
|
|
error_reporting(0);
|
2010-01-05 23:02:57 -05:00
|
|
|
|
|
|
|
if ( $current_blog->archived == '1' || $current_blog->spam == '1' || $current_blog->deleted == '1' ) {
|
|
|
|
status_header( 404 );
|
2010-02-03 13:19:56 -05:00
|
|
|
die( '404 — File not found.' );
|
2010-01-05 23:02:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !function_exists('wp_check_filetype') ) :
|
|
|
|
function wp_check_filetype($filename, $mimes = null) {
|
|
|
|
// Accepted MIME types are set here as PCRE unless provided.
|
|
|
|
$mimes = is_array($mimes) ? $mimes : array (
|
|
|
|
'jpg|jpeg|jpe' => 'image/jpeg',
|
|
|
|
'gif' => 'image/gif',
|
|
|
|
'png' => 'image/png',
|
|
|
|
'bmp' => 'image/bmp',
|
|
|
|
'tif|tiff' => 'image/tiff',
|
|
|
|
'ico' => 'image/x-icon',
|
|
|
|
'asf|asx|wax|wmv|wmx' => 'video/asf',
|
|
|
|
'avi' => 'video/avi',
|
|
|
|
'mov|qt' => 'video/quicktime',
|
|
|
|
'mpeg|mpg|mpe' => 'video/mpeg',
|
|
|
|
'txt|c|cc|h' => 'text/plain',
|
|
|
|
'rtx' => 'text/richtext',
|
|
|
|
'css' => 'text/css',
|
|
|
|
'htm|html' => 'text/html',
|
|
|
|
'mp3|mp4' => 'audio/mpeg',
|
|
|
|
'ra|ram' => 'audio/x-realaudio',
|
|
|
|
'wav' => 'audio/wav',
|
|
|
|
'ogg' => 'audio/ogg',
|
|
|
|
'mid|midi' => 'audio/midi',
|
|
|
|
'wma' => 'audio/wma',
|
|
|
|
'rtf' => 'application/rtf',
|
|
|
|
'js' => 'application/javascript',
|
|
|
|
'pdf' => 'application/pdf',
|
|
|
|
'doc' => 'application/msword',
|
|
|
|
'pot|pps|ppt' => 'application/vnd.ms-powerpoint',
|
|
|
|
'wri' => 'application/vnd.ms-write',
|
|
|
|
'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',
|
|
|
|
'mdb' => 'application/vnd.ms-access',
|
|
|
|
'mpp' => 'application/vnd.ms-project',
|
|
|
|
'swf' => 'application/x-shockwave-flash',
|
|
|
|
'class' => 'application/java',
|
|
|
|
'tar' => 'application/x-tar',
|
|
|
|
'zip' => 'application/zip',
|
|
|
|
'gz|gzip' => 'application/x-gzip',
|
|
|
|
'exe' => 'application/x-msdownload'
|
|
|
|
);
|
|
|
|
|
|
|
|
$type = false;
|
|
|
|
$ext = false;
|
|
|
|
|
2010-02-03 13:19:56 -05:00
|
|
|
foreach ( (array) $mimes as $ext_preg => $mime_match ) {
|
2010-01-05 23:02:57 -05:00
|
|
|
$ext_preg = '!\.(' . $ext_preg . ')$!i';
|
|
|
|
if ( preg_match($ext_preg, $filename, $ext_matches) ) {
|
|
|
|
$type = $mime_match;
|
|
|
|
$ext = $ext_matches[1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return compact('ext', 'type');
|
|
|
|
}
|
|
|
|
endif;
|
|
|
|
|
2010-02-02 11:32:19 -05:00
|
|
|
$file = BLOGUPLOADDIR . str_replace( '..', '', $_GET[ 'file' ] );
|
2010-01-05 23:02:57 -05:00
|
|
|
if ( !is_file( $file ) ) {
|
|
|
|
status_header( 404 );
|
2010-02-03 13:19:56 -05:00
|
|
|
die( '404 — File not found.' );
|
2010-01-05 23:02:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$mime = wp_check_filetype( $_SERVER[ 'REQUEST_URI' ] );
|
2010-02-03 13:19:56 -05:00
|
|
|
if( false === $mime[ 'type' ] && function_exists( 'mime_content_type' ) )
|
|
|
|
$mime[ 'type' ] = mime_content_type( $file );
|
2010-01-05 23:02:57 -05:00
|
|
|
|
2010-02-03 13:19:56 -05:00
|
|
|
if( $mime[ 'type' ] )
|
2010-01-05 23:02:57 -05:00
|
|
|
$mimetype = $mime[ 'type' ];
|
2010-02-03 13:19:56 -05:00
|
|
|
else
|
|
|
|
$mimetype = 'image/' . substr( $_SERVER[ 'REQUEST_URI' ], strrpos( $_SERVER[ 'REQUEST_URI' ], '.' ) + 1 );
|
|
|
|
|
|
|
|
header( 'Content-type: ' . $mimetype ); // always send this
|
2010-01-05 23:02:57 -05:00
|
|
|
if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) )
|
2010-02-03 13:19:56 -05:00
|
|
|
header( 'Content-Length: ' . filesize( $file ) );
|
2010-01-05 23:02:57 -05:00
|
|
|
|
|
|
|
// Optional support for X-Sendfile and X-Accel-Redirect
|
2010-02-03 13:19:56 -05:00
|
|
|
if ( WPMU_ACCEL_REDIRECT ) {
|
|
|
|
header( 'X-Accel-Redirect: ' . str_replace( WP_CONTENT_DIR, '', $file ) );
|
2010-01-05 23:02:57 -05:00
|
|
|
exit;
|
2010-02-03 13:19:56 -05:00
|
|
|
} elseif ( WPMU_SENDFILE ) {
|
|
|
|
header( 'X-Sendfile: ' . $file );
|
2010-01-05 23:02:57 -05:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2010-02-03 13:19:56 -05:00
|
|
|
$last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) );
|
|
|
|
$etag = '"' . md5( $last_modified ) . '"';
|
|
|
|
header( "Last-Modified: $last_modified GMT" );
|
|
|
|
header( 'ETag: ' . $etag );
|
|
|
|
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' );
|
2010-01-05 23:02:57 -05:00
|
|
|
|
|
|
|
// Support for Conditional GET
|
2010-02-03 13:19:56 -05:00
|
|
|
$client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false;
|
2010-01-05 23:02:57 -05:00
|
|
|
|
2010-02-03 13:19:56 -05:00
|
|
|
if( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) )
|
2010-01-05 23:02:57 -05:00
|
|
|
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = false;
|
2010-02-03 13:19:56 -05:00
|
|
|
|
|
|
|
$client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
|
2010-01-05 23:02:57 -05:00
|
|
|
// If string is empty, return 0. If not, attempt to parse into a timestamp
|
2010-02-03 13:19:56 -05:00
|
|
|
$client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
|
2010-01-05 23:02:57 -05:00
|
|
|
|
2010-01-26 17:49:05 -05:00
|
|
|
// Make a timestamp for our most recent modification...
|
2010-01-05 23:02:57 -05:00
|
|
|
$modified_timestamp = strtotime($last_modified);
|
|
|
|
|
2010-02-03 13:19:56 -05:00
|
|
|
if ( ( $client_last_modified && $client_etag )
|
|
|
|
? ( ( $client_modified_timestamp >= $modified_timestamp) && ( $client_etag == $etag ) )
|
|
|
|
: ( ( $client_modified_timestamp >= $modified_timestamp) || ( $client_etag == $etag ) )
|
|
|
|
) {
|
2010-01-05 23:02:57 -05:00
|
|
|
status_header( 304 );
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we made it this far, just serve the file
|
|
|
|
readfile( $file );
|
|
|
|
|
|
|
|
?>
|