当我生成csv时,它返回resourceid#7,但我无法下载我的csv。以下是我在ajax调用中调用的功能。
public function ExportShipments(){
$jsondata = $this->input->post();
// disable caching
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: text/csv; charset=utf-8");
header("Content-Disposition: attachment;filename=\"ShipmentManifest.csv\"");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
$file = fopen('php://output', 'w');
$header = array("AWBNO","Status");
// $exportData = $this->Error_model->getExportData($date,$clientid);
// echo gettype($jsondata); die;
$csvData = array();
$data = json_decode($jsondata['result'], true);
foreach($data as $row){
$row1['AWBNO'] = $row['ShippingID'];
$row1['Status'] = $row['response'];
$csvData[] = $row1;
}
fputcsv($file, $header);
foreach ($csvData as $key=>$line){
fputcsv($file,$line);
}
fclose($file);
die();
}
当我打印$ file时,它返回资源ID 我希望以csv格式下载文件