0

I'm offering a sermon downloading site and I have a user experiencing an issue with his download. Anyone have any ideas on how I can improve this code, or perhaps send better headers...

$path = "http://www.domain.com/sermon_files/".date("Y", $array["preached"])."/".$array["filename"];
$corePath = "/home/user/public_html/sermon_files/".date("Y", $array["preached"])."/".$array["filename"];
if (!file_exists($corePath)) {
    echo "An error has occured with this download.";    
} else {
    header("Pragma: public"); // required
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private", false); 
    header("Content-Type: audio/mp3");
    header("Content-Disposition: attachment; filename=\"".$array["title"]."\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($corePath));
    readfile($path);
    exit();
}
Ben
  • 60,438
  • 111
  • 314
  • 488

3 Answers3

0

Combine your PHP ( ? ) code with a server with X-Send available, lighttpd has it so does apache

empc
  • 132
  • 7
0

Watch out for Expires: 0 on downloads. This messes with IE6's tiny little brain and makes it think there is no data to save/open. Try expiring in a minute from access and see if that fixes the problem. Otherwise, tell us exactly what the problem is.

SpliFF
  • 38,186
  • 16
  • 91
  • 120
0

Take a look at this thread, I had similar problems: PHP: Force file download and IE, yet again. Also consider using Fiddler to capture the exact HTTP headers that are being sent to the client.

Community
  • 1
  • 1
Alex Weinstein
  • 9,823
  • 9
  • 42
  • 59