[eluser]GabrieleMartino[/eluser]
Hello,
I was wondering if is possible to download throught an ajax call.
I have the call through ajax
Code:
$('#download_file').on ('click', function (){
$.ajax({
dataType: "json" ,
url: base_url + "chat/download_file",
success: function(data){
alert("ok");
}
});
});
and a controller than is made
Code:
public function download_file(){
$this->load->helper('download');
$path = './uploads/'.$this->session->userdata('chat_id').'/files';
$path_complete = $path.'/';
$handle = opendir($path_complete);
$files = glob($path_complete.'*'); // get all file names
foreach($files as $file){ // iterate files
if(is_file($file))
echo ($file);
$data = file_get_contents($path_complete.$file); // Read the file's contents
$name = $file;
force_download($name, $data);
echo json_encode("Success");
}
}
The methods call the path controller but nothing happen on the screen.
Any idea!?