Я использую codeigniter и ajax для загрузки файла.возникают проблемы при загрузке файла с использованием 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 выполнять отлично и созданный PDF в папке pdfcache, проблема в том, что это не скачивая файлы, когда файл создано.
вот мой сценарий загрузки
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();
}
надеюсь, что вы понимаете Genius моя проблема
Возможный дубликат [Загрузить файл через ajax call php] (http://stackoverflow.com/questions/6668776/download-file-through-an-ajax-call-php) – stormdrain