How can I force a file download in all browsers?
<p>I am working on script which allows user to download pptx and zip files using php, but this script behaves different on different browsers. I tried many scripts available on the internet, but nothing worked properly so I made this one collecting chunks from different scripts. </p>

<ol>
<li>firefox => works perfect  </li>
<li>Opera   => Downloads file as a HTM file</li>
<li>Safari  => 0kb File    </li>
<li>IE      => Catching old file</li>
</ol>

<p>My Code:-</p>

<pre><code>// content type for pptx file 
$ctype = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
$file = "http://www.abc.com/presentation.pptx";
header("Pragma: public"); 
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-Type: ".$ctype); 
header("Content-Disposition: attachment; filename=\"".basename($file)."\";" ); 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: ".filesize($file)); 

ob_clean(); 
flush(); 
readfile( $file);
</code></pre>

<p>How can I get all browsers to reliably download the file instead of displaying the seemingly random behaviour above?</p>

<p>Edit: Below is the code that worked for me, I am not sure what was the problem, unwanted headers or file path ? I made both the changes and it worked. </p>

<pre><code>$ctype = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
$file = "Presentation3.pptx";
header("Pragma: public"); 
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Content-Type: ".$ctype); 
header("Content-Disposition: attachment; filename=\"".basename($file)."\";" ); 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: ".filesize($file)); 
readfile( $file); 
</code></pre>
