Php download zip archive big filesize
<p>Hihi,</p>

<p>I have a form with multiple check boxes where it allow user to select the brochures they want before they are prompted to download the zip file. The zip archive download function is working without problem. But I realized the download session will be terminated without downloading the entire file (say 8MB) and the downloaded zip file will turn out corrupted.</p>

<p>Referring to the codes below, it does not solve the problem. Anybody can advise what are the settings I need to look into or am I missing out any functionality?</p>

<pre><code>if($send) {     
    // Make sure program execution doesn't time out
    // Set maximum script execution time in seconds (0 means no limit)
    set_time_limit(0);

    $post = $_POST;     
    $file_folder = "pdf/";  // folder to load files
    $zip = new ZipArchive();    // Load zip library 
    $zip_name = "File-".time().".zip";          // Zip name
    if($zip-&gt;open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){       // Opening zip file to load files
        $error .=  "* Sorry ZIP creation failed at this time&lt;br/&gt;";
    }
    foreach($post['brochure'] as $file){                
        $zip-&gt;addFile($file_folder.$file);          // Adding files into zip
    }
    $zip-&gt;close();
    if(file_exists($zip_name)){
        // set headers push to download the zip
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: public");
        header('Content-type: application/zip');
        header("Content-Transfer-Encoding: Binary");
        header('Content-Disposition: attachment; filename="'.$zip_name.'"');
        header("Content-Length: ".filesize($zip_name)); 
        readfile($zip_name);
        // remove zip file is exists in temp path
        unlink($zip_name);

        $fp = @fopen($zip_name, "rb");
        if ($fp) {
         while(!feof($fp)) {
             print(fread($fp, 1024*8));
             flush(); // this is essential for large downloads
             if (connection_status()!=0) {
                 @fclose($file);
                 die();
             }
         }
         @fclose($file);
        }
    }
</code></pre>
