PHP: Forcing a download not working
<p>I have the following code to push a zip file for download.</p>

<pre><code>$filename = "ResourcePack_".time().".zip";
        $destination = $basepath."downloads/$filename";
        if($this-&gt;createdownload($files,$destination,false)){
            header("Cache-Control: public");
            header("Content-Description: File Transfer");
            header("Content-Length: ". filesize("$destination").";");
            header("Content-Disposition: attachment; filename='$filename'");
            header("Content-Type: application/octet-stream; "); 
            header("Content-Transfer-Encoding: binary");
            ob_end_flush();
            @readfile($destination);

            if(file_exists($destination)){
                unlink($destination);
            }
        }
</code></pre>

<p>I know the createdownload function is working to generate the zip file just fine because I see the file being created on the server. The problem is file is being written to the browser as a bunch of garbage instead of opening a download stream. Am I missing something in my headers?</p>

<h1>EDIT</h1>

<p>I was right. My problem is not with the php, but that calling the php file that generates this code via a JQuery $.ajax call is the problem. Using $.ajax automatically sets the Accept-Encoding request header to values incompatible with zip files. So, intead of using $.ajax I just used a simple window.open javascript command to call the same php page and it works just fine with the headers.</p>
