-
-
Save saturngod/4214171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************** | |
* Html form with hidden data called csv_hdr and csv_output. | |
*********************************/ | |
$(document).ready(function(){ | |
$("#btn_challenge_score_details").click(function (){ | |
var csv_hdr = $("#csv_hdr").val(); | |
var csv_output = $("#csv_output").val(); | |
var dataString = 'csv_hdr='+ csv_hdr + '&csv_output=' + csv_output; | |
//alert (dataString); return false; | |
$.ajax({ | |
type: "POST", | |
url: "<?=base_url()?>challenge/export_csv", | |
data: dataString, | |
cache:false, | |
success: | |
function(data){ | |
$("#message").html(data); | |
} | |
}); | |
return false; | |
}); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******** | |
* Controller method | |
***************************************************/ | |
function export_csv() | |
{ | |
$out = ''; | |
if (isset($_POST['csv_hdr'])) | |
{ | |
$out .= $_POST['csv_hdr']; | |
$out .= "\n"; | |
} | |
if (isset($_POST['csv_output'])) | |
{ | |
$out .= $_POST['csv_output']; | |
} | |
$file = 'ExportCSV'; | |
$filename = $file."_".date("Y-m-d_H-i",time()); | |
//Generate the CSV file header | |
header("Content-type: application/vnd.ms-excel"); | |
header("Content-disposition: csv" . date("Y-m-d") . ".csv"); | |
header("Content-disposition: attachment; filename=".$filename.".csv"); | |
print $out; | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment