class Downloads extends Controller { function Downloads() { parent::Controller(); $this->load->model('downloads_model'); $this->load->helper('text'); $this->load->library('pagination'); require_once(APPPATH.'rapyd/helpers/datehelper.php'); } function get_file() { $name = $this->session->userdata('filename'); $folder = 'files/'; ob_end_clean(); $path = $folder.$name; if (!is_file($path)) return $this->index(); if (connection_status()!=0) return(FALSE); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header("Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Content-Type: application/octet-stream"); header("Content-Length: ".(string)(filesize($path))); header($this->downloads_model->headers($name)); header("Content-Transfer-Encoding: binary\n"); if ($file = fopen($path, 'rb')) { while(!feof($file) and (connection_status()==0)) { print(fread($file, 1024*8)); flush(); } fclose($file); } $this->session->set_userdata(array('filename' => '')); return((connection_status()==0) and !connection_aborted()); } }