views:

123

answers:

0

These are large (20-60mb) quickbooks files. Seemingly at random, IE users who are downloading them get "server returned an invalid or unrecognized response", and the download fails.

Works 100% of the time in other browsers.

This is over SSL. These downloads are being forced, I've tried every variation of headers I have seen. Currently:

@ob_end_clean();
    if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off');

    header('Content-Type: application/force-download');
    header('Content-Disposition: attachment; filename="'.$file->original_name.'"');
    header("Content-Transfer-Encoding: binary");
    header('Accept-Ranges: bytes');


    header("Cache-Control: public, must-revalidate");
    header("Pragma: hack");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

    $size = filesize($_SERVER['DOCUMENT_ROOT'].'/uploads/'.$file->name);

    header("Content-Length: ".$size);

    $new_length = $size;
    /* output the file itself */
    $chunksize = 1*(1024*1024); //you may want to change this
    $bytes_send = 0;
    if ($file_h = fopen($_SERVER['DOCUMENT_ROOT'].'/uploads/'.$file->name, 'rb'))
    {

        while
            (!feof($file_h) && 
             (!connection_aborted()) && 
             ($bytes_send<$new_length) )
        {
            set_time_limit(5);
            $buffer = fread($file_h, $chunksize);
            echo($buffer); 
            flush();
            $bytes_send += strlen($buffer);
        }
    fclose($file_h);
    }

    die();