Changeset 12936 for trunk/wp-includes/ms-files.php
- Timestamp:
- 02/03/2010 06:19:56 PM (15 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/ms-files.php
r12935 r12936 10 10 11 11 define( 'SHORTINIT', true ); 12 require_once( dirname( dirname( __FILE__) ) . '/wp-load.php' ); // absolute includes are faster 13 require_once( WP_CONTENT_DIR . '/blogs.php' ); 14 exit(); 12 require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' ); 13 ms_default_constants( 'ms-files' ); 14 15 error_reporting(0); 16 17 if ( $current_blog->archived == '1' || $current_blog->spam == '1' || $current_blog->deleted == '1' ) { 18 status_header( 404 ); 19 die( '404 — File not found.' ); 20 } 21 22 if ( !function_exists('wp_check_filetype') ) : 23 function wp_check_filetype($filename, $mimes = null) { 24 // Accepted MIME types are set here as PCRE unless provided. 25 $mimes = is_array($mimes) ? $mimes : array ( 26 'jpg|jpeg|jpe' => 'image/jpeg', 27 'gif' => 'image/gif', 28 'png' => 'image/png', 29 'bmp' => 'image/bmp', 30 'tif|tiff' => 'image/tiff', 31 'ico' => 'image/x-icon', 32 'asf|asx|wax|wmv|wmx' => 'video/asf', 33 'avi' => 'video/avi', 34 'mov|qt' => 'video/quicktime', 35 'mpeg|mpg|mpe' => 'video/mpeg', 36 'txt|c|cc|h' => 'text/plain', 37 'rtx' => 'text/richtext', 38 'css' => 'text/css', 39 'htm|html' => 'text/html', 40 'mp3|mp4' => 'audio/mpeg', 41 'ra|ram' => 'audio/x-realaudio', 42 'wav' => 'audio/wav', 43 'ogg' => 'audio/ogg', 44 'mid|midi' => 'audio/midi', 45 'wma' => 'audio/wma', 46 'rtf' => 'application/rtf', 47 'js' => 'application/javascript', 48 'pdf' => 'application/pdf', 49 'doc' => 'application/msword', 50 'pot|pps|ppt' => 'application/vnd.ms-powerpoint', 51 'wri' => 'application/vnd.ms-write', 52 'xla|xls|xlt|xlw' => 'application/vnd.ms-excel', 53 'mdb' => 'application/vnd.ms-access', 54 'mpp' => 'application/vnd.ms-project', 55 'swf' => 'application/x-shockwave-flash', 56 'class' => 'application/java', 57 'tar' => 'application/x-tar', 58 'zip' => 'application/zip', 59 'gz|gzip' => 'application/x-gzip', 60 'exe' => 'application/x-msdownload' 61 ); 62 63 $type = false; 64 $ext = false; 65 66 foreach ( (array) $mimes as $ext_preg => $mime_match ) { 67 $ext_preg = '!\.(' . $ext_preg . ')$!i'; 68 if ( preg_match($ext_preg, $filename, $ext_matches) ) { 69 $type = $mime_match; 70 $ext = $ext_matches[1]; 71 break; 72 } 73 } 74 75 return compact('ext', 'type'); 76 } 77 endif; 78 79 $file = BLOGUPLOADDIR . str_replace( '..', '', $_GET[ 'file' ] ); 80 if ( !is_file( $file ) ) { 81 status_header( 404 ); 82 die( '404 — File not found.' ); 83 } 84 85 $mime = wp_check_filetype( $_SERVER[ 'REQUEST_URI' ] ); 86 if( false === $mime[ 'type' ] && function_exists( 'mime_content_type' ) ) 87 $mime[ 'type' ] = mime_content_type( $file ); 88 89 if( $mime[ 'type' ] ) 90 $mimetype = $mime[ 'type' ]; 91 else 92 $mimetype = 'image/' . substr( $_SERVER[ 'REQUEST_URI' ], strrpos( $_SERVER[ 'REQUEST_URI' ], '.' ) + 1 ); 93 94 header( 'Content-type: ' . $mimetype ); // always send this 95 if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) 96 header( 'Content-Length: ' . filesize( $file ) ); 97 98 // Optional support for X-Sendfile and X-Accel-Redirect 99 if ( WPMU_ACCEL_REDIRECT ) { 100 header( 'X-Accel-Redirect: ' . str_replace( WP_CONTENT_DIR, '', $file ) ); 101 exit; 102 } elseif ( WPMU_SENDFILE ) { 103 header( 'X-Sendfile: ' . $file ); 104 exit; 105 } 106 107 $last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) ); 108 $etag = '"' . md5( $last_modified ) . '"'; 109 header( "Last-Modified: $last_modified GMT" ); 110 header( 'ETag: ' . $etag ); 111 header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' ); 112 113 // Support for Conditional GET 114 $client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false; 115 116 if( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) 117 $_SERVER['HTTP_IF_MODIFIED_SINCE'] = false; 118 119 $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); 120 // If string is empty, return 0. If not, attempt to parse into a timestamp 121 $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0; 122 123 // Make a timestamp for our most recent modification... 124 $modified_timestamp = strtotime($last_modified); 125 126 if ( ( $client_last_modified && $client_etag ) 127 ? ( ( $client_modified_timestamp >= $modified_timestamp) && ( $client_etag == $etag ) ) 128 : ( ( $client_modified_timestamp >= $modified_timestamp) || ( $client_etag == $etag ) ) 129 ) { 130 status_header( 304 ); 131 exit; 132 } 133 134 // If we made it this far, just serve the file 135 readfile( $file ); 136 137 ?>
Note: See TracChangeset
for help on using the changeset viewer.