natatkinson
7/21/2014 - 3:55 PM

Force Download of File

Force Download of File

<?php

$type = "application/force-download"; 
$tmp_loc = "reg_data.txt";
$header_file = $tmp_loc;
         header("Pragma: public");
         header("Expires: 0");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Cache-Control: public", false);
         header("Content-Description: File Transfer");
         header("Content-Type: " . $type);
         header("Accept-Ranges: bytes");
         header("Content-Disposition: attachment; filename=\"" . $header_file . "\"");
         header("Content-Transfer-Encoding: binary");
         header("Content-Length: " . filesize($tmp_loc));



 
               
         // Send file for download
         if ($stream = fopen($tmp_loc, 'rb')){
         	while(!feof($stream) && connection_status() == 0){
            	//reset time limit for big files
                //set_time_limit(0);
                print(fread($stream,1024*8));
                flush();
             }
             fclose($stream);
         }