0

I want to force a download.. In IE I get an error but there are no problems in FF

header("Content-Type: application/force-download\n");
header("Content-Disposition: attachment; filename=test.txt");

echo 'test file';
clarkk
  • 27,151
  • 72
  • 200
  • 340

2 Answers2

5

I just googled about your curious application/force-download mime type. I dont know, who did "invented" this, but it seems, that it just dont exists. See http://mimeapplication.org/force-download.html

This means, the IE probably dont like it. Use application/octet-stream instead. As far as I remember firefox opens a download dialog for every mime-type, that is either registered with "show download dialog", or it simply doesnt know. In this case FF probably doesnt know the type.

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
  • it works, but now I can't preset the filename... header("Content-Type: application/octet-stream\n"); header("Content-Disposition: attachment; filename=test.txt"); – clarkk Apr 08 '11 at 12:13
  • Dont know, if thats the reason for your behaviour, but dont put a newline at the end. – KingCrunch Apr 08 '11 at 18:13
0

This might help you , it works for me

header('Content-Type: application/force-download');
header("Content-disposition: attachment; filename=$filename");
flush();
readfile($filename);
exit;

you can add other headers if desired :)

sakhunzai
  • 13,900
  • 23
  • 98
  • 159