title: Correct headers and mime_type for PHP http streaming
body: <p>I've been fighting with this for a few days now. I can't seem to get anything to play through PHP. I'm trying to play a <code>.m4a</code> audio file through php and all it does is show the HTML5 player in Chrome but the file does not load. </p>
  
  <p><strong>I've tried numerous tricks from other posts here and nothing seems to make a difference.</strong> </p>
  
  <p>Here is some back end info.</p>
  
  <p>Apache/Linux Server with PHP-FPM running <a href="http://h264.code-shop.com/trac/wiki/Mod-H264-Streaming-Apache-Version2" rel="nofollow">H264 Streaming module</a>. 
  <code>AddType audio/mp4 m4a</code> is added in the vhost file.</p>
  
  <p>All files are <code>.m4a</code> that was encoded with ffmpeg and used the <code>-c:a aac -strict experimental</code> in ffmpeg as the audio codec. The file itself plays just fine directly in the browser, just not through PHP. Funny thing is when I changed the mime to audio/acc it played in the browser but through quicktime player. I need it to be native HTML5 m4a. </p>
  
  <p>Here is the PHP code I'm trying to use. I've tried many combos including using Content-Disposition but that tries to download and save it then. i don't want that.</p>
  
  <pre><code>        $size = filesize($realfile);
          $mimes = "audio/mp4";
          if(file_exists($realfile)){
              header('Accept-Ranges: bytes');
              header('Content-Length: ' . $size);
              header('Content-Range: bytes 0-'.($size - 1).'/'.$size);
              header('Content-Type: '.$mimes);
              readfile($realfile);
          }else{
              header("HTTP/1.1 403 Forbidden");
          }
  </code></pre>
  
  <p>Here are the response headers using the PHP URL. (Does NOT play)</p>
  
  <pre><code>Accept-Ranges:bytes
  Access-Control-Allow-Origin:*
  Connection:Keep-Alive
  Content-Length:3340918
  Content-Range:bytes 0-3340917/3340918
  Content-Type:audio/mp4
  Date:Fri, 17 Apr 2015 21:47:21 GMT
  Keep-Alive:timeout=5, max=100
  Server:Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9
  X-Powered-By:PHP/5.5.22
  </code></pre>
  
  <p>Here is the response headers from the URL of the file directly. (Plays fine)</p>
  
  <pre><code>Accept-Ranges:bytes
  Access-Control-Allow-Origin:*
  Connection:Keep-Alive
  Content-Length:3340918
  Content-Range:bytes 0-3340917/3340918
  Content-Type:audio/mp4
  Date:Fri, 17 Apr 2015 21:29:04 GMT
  ETag:"32fa76-5139745cc934f"
  Keep-Alive:timeout=5, max=100
  Last-Modified:Mon, 13 Apr 2015 08:55:15 GMT
  Server:Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_fcgid/2.3.9
  </code></pre>
  
  <p>Any help on this would be great. </p>
  
  <p><strong>EDIT: I finally gave up with this code. I found a PHP script on GitHub that does exactly what I need and it works perfectly.</strong></p>
  
  <p><a href="https://github.com/tuxxin/MP4Streaming" rel="nofollow">https://github.com/tuxxin/MP4Streaming</a></p>