diff --git src/wp-includes/ms-files.php src/wp-includes/ms-files.php
index e5c1db3f89..f9bb8004e0 100644
|
|
$etag = '"' . md5( $last_modified ) . '"'; |
56 | 56 | header( "Last-Modified: $last_modified GMT" ); |
57 | 57 | header( 'ETag: ' . $etag ); |
58 | 58 | header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' ); |
| 59 | // Note support for range requests. |
| 60 | header( 'Accept-Ranges: bytes' ); |
59 | 61 | |
60 | 62 | // Support for Conditional GET - use stripslashes to avoid formatting.php dependency |
61 | 63 | $client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false; |
… |
… |
if ( ( $client_last_modified && $client_etag ) |
78 | 80 | exit; |
79 | 81 | } |
80 | 82 | |
| 83 | // Support for byte-range requests |
| 84 | // Safari requires this and will not play mp4 files (and possibly others) |
| 85 | // without it. |
| 86 | if ( ! empty( $_SERVER['HTTP_RANGE'] ) && preg_match('/^bytes=(\d+)-(\d+)$/i', $_SERVER['HTTP_RANGE'], $m ) ) { |
| 87 | $byte_start = (int) $m[1]; |
| 88 | $byte_end = (int) $m[2]; |
| 89 | if ( filesize( $file ) - 1 < $byte_end || $byte_end < $byte_start ) { |
| 90 | status_header( 416 ); |
| 91 | die( '416 — Request Range Not Satisfiable.' ); |
| 92 | } |
| 93 | status_header( 206 ); |
| 94 | header( 'Content-Range: bytes ' . $byte_start . '-' . $byte_end . '/' . filesize( $file ) ); |
| 95 | header( 'Content-Length: ' . ($byte_end - $byte_start + 1) ); |
| 96 | |
| 97 | // Stream the file in 1kb chunks to avoid overloading PHP memory usage for large files. |
| 98 | $handle = fopen( $file, "r" ); |
| 99 | fseek( $handle, $byte_start ); |
| 100 | $chunk_position = $byte_start; |
| 101 | while ( $chunk_position <= $byte_end && !feof($handle) ) { |
| 102 | $chunk_length = min( 1024, $byte_end - $chunk_position + 1 ); |
| 103 | print fread( $handle, $chunk_length ); |
| 104 | $chunk_position += 1024; |
| 105 | flush(); |
| 106 | } |
| 107 | fclose( $handle ); |
| 108 | flush(); |
| 109 | exit; |
| 110 | } |
| 111 | |
81 | 112 | // If we made it this far, just serve the file |
82 | 113 | readfile( $file ); |
83 | 114 | flush(); |