<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Download extends MX_Controller 
{

	public function __construct() {
		parent::__construct();
                $user = $this->session->userdata ( 'userInfo' );
		$this->vservices->setApiUrl($this->config->item('api_url'));
		$this->vservices->setConnection($this->curl);
		$this->vservices->setUserId($user['us_id']);
	}
	
	public function getFile () {
                $data=  $this->input->post('data');
                $treeArray=  json_decode($data,TRUE);
           
                if ((count($treeArray)==1) && ($treeArray[0]['type']=='file'))
                {
                    $file=$treeArray[0];
                    echo $file['name'];
                    $file = file_get_contents($treeArray[0]['fileurl']);  
                    $local_file="".$treeArray[0]['name'];
                    file_put_contents($local_file, $file);
                    $download_rate = 512;
                    $download_file = $treeArray[0]['name']; 
                }
                die();
                
                
                
                
                
                
                
                
                
               


   // send headers

    header('Cache-control: private');
    header('Content-Type: application/octet-stream');
    header('Content-Length: '.filesize($local_file));
    header('Content-Disposition: filename='.$download_file);
 
    
    // flush content
    flush();
 
    // open file stream
    $file = fopen($local_file, "r");
 
    while (!feof($file)) {
 
        // send the current file part to the browser
        print fread($file, round($download_rate * 1024));
 
        // flush the content to the browser
        flush();
 
        // sleep one second
        sleep(1);
    }
 
    // close file stream
    fclose($file);
    
                exit;
            
	}
       

}

/* End of file privatecontent.php */
/* Location: ./application/modules/ajax/controllers/privatecontent.php */