I'm trying to send my mp3 files through a PHP script in order to hide the path to the file in the HTML. Everything works perfectly fine except half way into the mp3 chrome gives me a GET [URL] error. And the rest of the mp3 is just blank. The audio tag thinks it's still reading the file, but there is no sound.
This is how I'm sending the mp3 file from php:
if (file_exists($filename)) {
header("Content-Transfer-Encoding: binary");
header("Content-Type: audio/mpeg");
header('Content-length: ' . filesize($filename));
header('Content-Disposition: inline; filename="' . $filename . '"');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
readfile($filename);
exit;
}
else {
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
echo "no file";
}
Edit: I added the Etag header. It seems to make things better. The problem still occurs but not as often. :-/
Edit2: I have noticed that the request headers sent to my PHP file is different from the headers sent directly to the mp3 file. Actually there's a HTTP_RANGE request sent to the mp3 file, but this range request is missing when I try to fetch things from PHP. (This is in Chrome). Any idea why this might be ?