tags:

views:

58

answers:

1
 header('Content-Description: File Transfer');
 header('Content-Type: application/octet-stream');
 header('Content-Disposition: attachment; filename='.basename($file));
 header('Content-Transfer-Encoding: binary');
 header('Expires: 0');
 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 header('Pragma: public');
 header('Content-Length: ' . filesize($file));
 ob_clean();
 flush();
 readfile($file);

i downloaded file but can't open file ? why ?

A: 

Try the below code (untested):

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
@ob_end_clean();
readfile($file);
exit();
Lucanos
Isn't one of the things output buffering accomplishes allowing headers to go through before any content?
Arda Xi
@Arda Xi is correct, ob_clean does not impact headers.
Charles
I stand corrected (that's why I said "I think" rather than making a definite assertion). Thanks for the pick-up on that guys - I learn something new every day.
Lucanos
thank all very much
Chameron