ms-files.php 2.6 KB

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