ファイルのダウンロードに codeigniter と ajax を使用しています。
私の Ajax リクエスト
$('.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)
{}
});
});
コントローラーにあるPDF関数を呼び出しています
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 と PHP は完全に実行され、pdfcache フォルダーに PDF が作成されます。問題は、ファイルの作成時にファイルがダウンロードされないことです。
ここに私のダウンロードスクリプトがあります
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();
}
天才が私の問題を理解してくれることを願っています