why ob_clean and flush ?
Posted: Sun May 24, 2009 3:26 pm
Hello,
I would like to know why do I need to use ob_clean and flush in this example (in which I want to force a download) and what they exactly do.
thanks!
I would like to know why do I need to use ob_clean and flush in this example (in which I want to force a download) and what they exactly do.
thanks!
Code: Select all
//force a download
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
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);
exit;
}
?>