title: ERR_CONTENT_LENGTH_MISMATCH when loading video in chrome
body: <p>So I get this error when some of the video plays. When Chrome completely downloads the video, it stops playing with this error. Also the status of the request changes from 206 to (failed) and then Chrome sends some other requests with <code>Range:bytes=2990775-</code> and the server response is:</p>
  
  <pre><code>Accept-Ranges:bytes
  Cache-Control:private
  Connection:keep-alive
  Content-Disposition:attachment; filename="About The Author.mp4"
  Content-Length:0
  Content-Range:bytes 2990775-2990775/2990776
  Content-Transfer-Encoding:binary
  Content-Type:video/mp4
  Date:Tue, 14 Feb 2017 13:46:24 GMT
  Last-Modified:Wed, 08 Feb 2017 05:43:27 GMT
  Pragma:public
  Server:Apache/2
  Vary:User-Agent
  X-Powered-By:PHP/5.4.45
  </code></pre>
  
  <p>I have another website on the same server and it works fine there.</p>
  
  <p>Here is my PHP code:</p>
  
  <pre><code>        $filesize = filesize($resource-&gt;path);
  
          $matches = explode("-", substr($_SERVER['HTTP_RANGE'],6));
          if (empty($matches[1]))
          {
              $matches[1] = $filesize - 1;
          }
  
          $offset = intval($matches[0]);
          $length = intval($matches[1]) - $offset;
  
          $file = fopen($resource-&gt;path, 'r');
  
          fseek($file, $offset);
  
          $data = fread($file, $length);
          fclose($file);
  
          header('HTTP/1.1 206 Partial Content');
          header('Content-Range: bytes ' . $offset . '-' . ($offset + $length) . '/' . $filesize);
  
          header('Pragma: public');   
          header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($resource-&gt;path)).' GMT');
          header('Cache-Control: private',false);
          header('Content-Type: ' . $mime);
          header('Content-Length: ' . ($length + 1));
          header('Content-Disposition: attachment; filename="' . $resource-&gt;filename . '"');
          header('Content-Transfer-Encoding: binary');
          header('Accept-Ranges: bytes');
  
          print($data);
  </code></pre>
  
  <p>Sorry for my bad english.</p>