i am using codeigniter and ajax for downloading a file.
My Ajax Request
$('.exporter').bind('click',function()
{
var callfunction = 'reportprints/print_'+$(this).attr('id').toLowerCase();
var Query = $('#exportQuery').val();
$.ajax({
url: callfunction,
type: 'POST',
dataType: 'html',
data:{q:Query},
success: function(output)
{}
});
});
it's calling my PDF Function which are in Controller
public function print_pdf()
{
$Query = $this->input->post('q');
// set document information
$this->pdf->SetAuthor('PrimexOne Exchange');
$filename = $this->makefilename('pdf','DSP');
$this->pdf->SetTitle('Daily Sales Report - '.date('d/m/Y'));
$this->pdf->SetSubject('PrimexOne Sales Report');
$this->pdf->SetKeywords('keywords');
$this->pdf->SetFont('helvetica', 'N', 12);
// add a page
//$this->pdf->AddPage();
// write html on PDF
$this->pdf->Cell(0,10,'Welcome in PrimexOne');
//Creating FileName
$filepath = APPPATH.'cache/pdfcache/';
$fullname = $filepath.$filename;
$this->pdf->Output($fullname, 'F');
$this->downloadfile(array('format'=>'pdf','filename'=>$filename,'filepath'=>$fullname));
}
ajax and PHP perform perfectly and created PDF in pdfcache folder, problem is it's not downloading files when file created.
here is my downloading script
public function downloadfile($arr)
{
$mime = 'application/force-download';
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.$arr['filename'].'"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
readfile($arr['filepath']);
exit();
}
hope you Genius understand my problem