Google Chrome does not fulfill the request if the Partial Content header is set

I am trying to transfer an mp3 file to SoundManager with a partial HTTP / 1.1 content header to provide some protection for my media files and also allow users to search for different places in the track. The code I use in IE7-10, Firefox, Safari and Opera, but refuses to work in Google Chrome. If I were to remove the Partial Content header, it would play the file, but would not allow the user to search.

When viewing the network tab in the Chrome Developer Tools, there are 2 requests, one is stuck in a standby state, and the other has a cancel status. both of these requests are 13B in size. The file I'm trying to play is 9.11MB.

Below is the code that I use to set the headers and read the file.

$name = $_GET['name']; $file_size = filesize($file); $file = "C:\xampp\htdocs\..\protected\music\testsong.mp3"; // song, user and all other checks are performed before this to get the file path. $etag = md5(uniqid(rand(), true)); $open_file = fopen($file, 'rb'); if( !$open_file ) throw new Exception('Could not open file'); $start = 0; $end = $file_size - 1; if( isset($_SERVER['HTTP_RANGE']) && !empty($_SERVER['HTTP_RANGE']) ) { $range = explode('-', substr($_SERVER['HTTP_RANGE'], strlen('bytes='))); $start = $range[0]; if( $range[1] > 0 ) $end = $range[1]; header('HTTP/1.1 206 Partial Content'); header('Status: 206'); header('Accept-Ranges: bytes'); header('Content-Range: ' . $_SERVER['HTTP_RANGE'] . '/' . $file_size); header('Content-Length: ' . ($end - $start + 1)); } else header('Content-Length: ' . $file_size); header('Content-Type: ' . $content_type); if( $download ) header('Content-Disposition: attachment; filename="' . $name . '"'); header('Last-Modified: ' . date('D, d MYH:i:s \G\M\T', filemtime($file))); header('ETag: "' . $etag . '"'); header('Expires: 0'); header('Pragma: no-cache'); header('Cache-Control: must-revalidate'); if( $start > 0 ) fseek($open_file, $start); $bytes_position = $start; while( !feof($open_file) && $bytes_position <= $end ) { if( connection_aborted() || connection_status() != 0 ) throw New Exception('Connection Aborted'); $chunk = 1048000; if( $bytes_position + $chunk > $end + 1 ) $chunk = $end - $bytes_position + 1; $chunk = fread($open_file, $chunk); if( !$chunk ) throw New Exception('Could not read file'); print($chunk); flush(); $bytes_position += $chunk; } fclose($open_file); 
+8
google-chrome php streaming
source share
1 answer

I'm sure the problem you are facing is the content range header

try this instead

 header('Content-Range: bytes ' . $start . '-' . $end . '/' . $file_size); 
+1
source share

All Articles