Hi all
I've written a PHP script thats part of a site ive made for an online music library.
The script is parsed a few get parameters and then opens an mp3 from a secure part of the web server that isnt under the public web accessible folders.
All straight forward.
The issue is that in safari, and ONLY safari, i cant make this browser cache the files its download via the php file. every time the url is accessed safari goes and downloads the stream again and never uses its cache.
Ive seen many online examples of code where people are trying to get php to STOP caching, but in my case I want it to. And as I say, ive made this work on the majority of browsers. Its just safari being stubborn.
The basic code i have serving the file is...
$filename = $tracktoplay[0];
$contents = fread(fopen($filename, "rb"), filesize($filename));
header('Content-type: audio/mpeg');
header('Content-length: ' . (string)filesize($filename));
// get date and add a month then format
$str_date = date("D, d M Y H:i:s");// current date
$str_date=strtotime(date("D, d M Y H:i:s", strtotime($str_date)) . " +1 month");
$str_date=gmdate("D, d M Y H:i:s", $str_date)." GMT";
header("Last-Modified: ".$str_date);
header('Expires: '.$str_date);
header('Cache-Control: public'); // HTTP/1.1
echo $contents;
Now ive tried 101 combinations of headers, using many others not in the code shown above such as "Expires", "Pragma" and "ETag". I understand some headers over rule others etc. Anyhow, the mp3 served via this code stays cached in all browsers ive tested except in safari as it just seems to ignore the headers i send or require some other explicit headers to be defined in order to work.
Ive spent ages going through other peoples general experiences of trying to serve files in different ways as well. For example, the main php site has a lot of good examples on their manual page about the header command. Still, nothing has ultimately helped me get around this issue.
Has anyone managed to get safari caching served files??? If so, please let me know the magic combination of headers that made it possible.
Thanks for any help!