I have a PHP app that creates a CSV file which is forced to download using headers. Here\'s the relevant part of the code:
header(\'Content-Type: applicatio
Here is the answer:
It's work!
You need three different parts of code:
HTML
Download<&/a>
JQuery
$('#download_btn').click(function(){
window.location.href = '=base_url()?>/?file==$file;?>&download=1';
}).focusout (function(){
window.location.href = '=base_url()?>';
return false;
});
PHP
if(isset($_GET['download']) && isset($_GET['file'])){
$zip_path = 'path_to/'.$_GET['file'].'.zip';
if(file_exists($zip_path)){
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="'.basename($zip_path).'"');
header('Content-Length: ' . filesize($zip_path));
header('Location: '.$zip_path);
}
}