You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

84 lines
2.6 KiB

  1. <?php
  2. /**
  3. * Multisite upload handler.
  4. *
  5. * @since 3.0.0
  6. *
  7. * @package WordPress
  8. * @subpackage Multisite
  9. */
  10. define( 'SHORTINIT', true );
  11. require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
  12. if ( !is_multisite() )
  13. die( 'Multisite support not enabled' );
  14. ms_file_constants();
  15. error_reporting( 0 );
  16. if ( $current_blog->archived == '1' || $current_blog->spam == '1' || $current_blog->deleted == '1' ) {
  17. status_header( 404 );
  18. die( '404 &#8212; File not found.' );
  19. }
  20. $file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET[ 'file' ] );
  21. if ( !is_file( $file ) ) {
  22. status_header( 404 );
  23. die( '404 &#8212; File not found.' );
  24. }
  25. $mime = wp_check_filetype( $file );
  26. if ( false === $mime[ 'type' ] && function_exists( 'mime_content_type' ) )
  27. $mime[ 'type' ] = mime_content_type( $file );
  28. if ( $mime[ 'type' ] )
  29. $mimetype = $mime[ 'type' ];
  30. else
  31. $mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 );
  32. header( 'Content-Type: ' . $mimetype ); // always send this
  33. if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) )
  34. header( 'Content-Length: ' . filesize( $file ) );
  35. // Optional support for X-Sendfile and X-Accel-Redirect
  36. if ( WPMU_ACCEL_REDIRECT ) {
  37. header( 'X-Accel-Redirect: ' . str_replace( WP_CONTENT_DIR, '', $file ) );
  38. exit;
  39. } elseif ( WPMU_SENDFILE ) {
  40. header( 'X-Sendfile: ' . $file );
  41. exit;
  42. }
  43. $last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) );
  44. $etag = '"' . md5( $last_modified ) . '"';
  45. header( "Last-Modified: $last_modified GMT" );
  46. header( 'ETag: ' . $etag );
  47. header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' );
  48. // Support for Conditional GET - use stripslashes to avoid formatting.php dependency
  49. $client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false;
  50. if ( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) )
  51. $_SERVER['HTTP_IF_MODIFIED_SINCE'] = false;
  52. $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
  53. // If string is empty, return 0. If not, attempt to parse into a timestamp
  54. $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
  55. // Make a timestamp for our most recent modification...
  56. $modified_timestamp = strtotime($last_modified);
  57. if ( ( $client_last_modified && $client_etag )
  58. ? ( ( $client_modified_timestamp >= $modified_timestamp) && ( $client_etag == $etag ) )
  59. : ( ( $client_modified_timestamp >= $modified_timestamp) || ( $client_etag == $etag ) )
  60. ) {
  61. status_header( 304 );
  62. exit;
  63. }
  64. // If we made it this far, just serve the file
  65. readfile( $file );
  66. flush();