0

I'm trying to force a download so this is my code:

$file = 'test.m4r';
$mime = 'audio/aac';
header("Pragma: public"); // required
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header('Content-Description: File Transfer');
header("Content-Type: $mime");
header('Content-Length: ' . filesize($file));          
header('Content-Disposition: attachment; filename=' . basename($file));
readfile($file);

The file extension should be .m4r, even though the mime is aac. On some computers it's downloaded as test.m4r, while on other computers, the file has extension of test.m4r.acc. How do I fix this problem?

Thank you!

Patrick
  • 4,815
  • 11
  • 52
  • 55

2 Answers2

1

You can lie about the mimetype, but besides that there isn't anything you can do. Try:

"application/octet-stream"

This might work, and is the default for unknown filetypes etc.

grvpanchal
  • 266
  • 1
  • 3
  • 17
Jani Hartikainen
  • 42,745
  • 10
  • 68
  • 86
1

try this one

<?php header("Content-Type: application/force-download"); ?>